sequence
stringlengths 1.25k
34.6k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '20', '336']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'call', 'children': ['7', '12']},{'id': '7', 'type': 'attribute', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Dut'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': '"Start DUT communication"'},{'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '16', 'type': 'dictionary', 'children': ['17']},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'<->'"},{'id': '20', 'type': 'while_statement', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Dut'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_run'},{'id': '24', 'type': 'block', 'children': ['25', '33']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Dut'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_sem'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'acquire'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'try_statement', 'children': ['34', '332']},{'id': '34', 'type': 'block', 'children': ['35', '45', '133', '233', '262']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dut'},{'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': 'Dut'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_signalled_duts'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'is'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'waiting_for_response'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52', '58', '68', '76', '103', '109', '124', '132']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'waiting_for_response'},{'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': 'dut'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_read_response'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'if_statement', 'children': ['69', '74']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': 'is'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'continue_statement', 'children': []},{'id': '76', 'type': 'if_statement', 'children': ['77', '84']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'CliResponse'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'set_response_time'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_timedelta'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'waiting_for_response'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"Got response"'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '120', 'type': 'dictionary', 'children': ['121']},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '123', 'type': 'string', 'children': [], 'value': "'<->'"},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'continue_statement', 'children': []},{'id': '133', 'type': 'if_statement', 'children': ['134', '139']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': 'is'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'block', 'children': ['140', '146', '152', '169', '199', '205', '232']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'query'},{'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': 'dut'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '159', 'type': 'argument_list', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '165', 'type': 'dictionary', 'children': ['166']},{'id': '166', 'type': 'pair', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '168', 'type': 'string', 'children': [], 'value': "'-->'"},{'id': '169', 'type': 'try_statement', 'children': ['170', '180']},{'id': '170', 'type': 'block', 'children': ['171']},{'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': 'dut'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'writeline'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '180', 'type': 'except_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '182', 'type': 'block', 'children': ['183', '190', '198']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '188', 'type': 'unary_operator', 'children': ['189'], 'value': '-'},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'continue_statement', 'children': []},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '205', 'type': 'if_statement', 'children': ['206', '209', '216']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'waiting_for_response'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '216', 'type': 'else_clause', 'children': ['217']},{'id': '217', 'type': 'block', 'children': ['218', '224']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '223', 'type': 'integer', 'children': [], 'value': '0'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '231']},{'id': '226', 'type': 'attribute', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'continue_statement', 'children': []},{'id': '233', 'type': 'try_statement', 'children': ['234', '243']},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'except_clause', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '245', 'type': 'block', 'children': ['246', '253', '261']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '251', 'type': 'unary_operator', 'children': ['252'], 'value': '-'},{'id': '252', 'type': 'integer', 'children': [], 'value': '1'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'continue_statement', 'children': []},{'id': '262', 'type': 'if_statement', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '264', 'type': 'block', 'children': ['265', '279', '288', '297', '317']},{'id': '265', 'type': 'if_statement', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'store_traces'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '277']},{'id': '272', 'type': 'attribute', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'traces'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'EventObject'},{'id': '282', 'type': 'argument_list', 'children': ['283', '286', '287']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'EventTypes'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'DUT_LINE_RECEIVED'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'check_retcode'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '297', 'type': 'if_statement', 'children': ['298', '301']},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '300'], 'value': 'is'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '300', 'type': 'None', 'children': []},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': '"unrequested retcode"'},{'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '313', 'type': 'dictionary', 'children': ['314']},{'id': '314', 'type': 'pair', 'children': ['315', '316']},{'id': '315', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '316', 'type': 'string', 'children': [], 'value': "'!<-'"},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '324']},{'id': '319', 'type': 'attribute', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '324', 'type': 'argument_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '328', 'type': 'dictionary', 'children': ['329']},{'id': '329', 'type': 'pair', 'children': ['330', '331']},{'id': '330', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '331', 'type': 'string', 'children': [], 'value': "'<<<'"},{'id': '332', 'type': 'except_clause', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'pass_statement', 'children': []},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '343']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'Dut'},{'id': '341', 'type': 'identifier', 'children': [], 'value': '_logger'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': '"End DUT communication"'},{'id': '345', 'type': 'keyword_argument', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '347', 'type': 'dictionary', 'children': ['348']},{'id': '348', 'type': 'pair', 'children': ['349', '350']},{'id': '349', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '350', 'type': 'string', 'children': [], 'value': "'<->'"} | def run():
Dut._logger.debug("Start DUT communication", extra={'type': '<->'})
while Dut._run:
Dut._sem.acquire()
try:
dut = Dut._signalled_duts.pop()
if dut.waiting_for_response is not None:
item = dut.waiting_for_response
dut.response_coming_in = dut._read_response()
if dut.response_coming_in is None:
continue
if isinstance(dut.response_coming_in, CliResponse):
dut.response_coming_in.set_response_time(item.get_timedelta(dut.get_time()))
dut.waiting_for_response = None
dut.logger.debug("Got response", extra={'type': '<->'})
dut.response_received.set()
continue
if dut.query is not None:
item = dut.query
dut.query = None
dut.logger.info(item.cmd, extra={'type': '-->'})
try:
dut.writeline(item.cmd)
except RuntimeError:
dut.response_coming_in = -1
dut.response_received.set()
continue
dut.prev = item
if item.wait:
dut.waiting_for_response = item
else:
dut.query_timeout = 0
dut.response_received.set()
continue
try:
line = dut.readline()
except RuntimeError:
dut.response_coming_in = -1
dut.response_received.set()
continue
if line:
if dut.store_traces:
dut.traces.append(line)
EventObject(EventTypes.DUT_LINE_RECEIVED, dut, line)
retcode = dut.check_retcode(line)
if retcode is not None:
dut.logger.warning("unrequested retcode", extra={'type': '!<-'})
dut.logger.debug(line, extra={'type': '<<<'})
except IndexError:
pass
Dut._logger.debug("End DUT communication", extra={'type': '<->'}) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '21', '30', '39', '80', '90', '104', '129']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'''\n Write a Python dictionary as JSON to a file.\n :param content: Dictionary of key-value pairs to save to a file\n :param filepath: Path where the file is to be created\n :param filename: Name of the file to be created\n :param indent: You can use this to specify indent level for pretty printing the file\n :param keys_to_write: array of keys that are to be picked from data and written to file.\n Default is None, when all data is written to file.\n :return: Path of file used\n :raises OSError, EnvironmentError, ValueError\n '''"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'conditional_expression', 'children': ['25', '26', '27'], 'value': 'if'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'conditional_expression', 'children': ['34', '35', '36'], 'value': 'if'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '39', 'type': 'if_statement', 'children': ['40', '49']},{'id': '40', 'type': 'not_operator', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'try_statement', 'children': ['51', '59']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '59', 'type': 'except_clause', 'children': ['60', '64']},{'id': '60', 'type': 'as_pattern', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '62', 'type': 'as_pattern_target', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '64', 'type': 'block', 'children': ['65', '79']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"Error while creating directory: {}"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '79', 'type': 'raise_statement', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_ends_with'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'string', 'children': [], 'value': '".json"'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_ends_with'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '104', 'type': 'if_statement', 'children': ['105', '106', '123']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '106', 'type': 'block', 'children': ['107', '111']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '110', 'type': 'dictionary', 'children': []},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '129', 'type': 'try_statement', 'children': ['130', '159', '180']},{'id': '130', 'type': 'block', 'children': ['131', '138', '149']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '134', 'type': 'conditional_expression', 'children': ['135', '136', '137'], 'value': 'if'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '137', 'type': 'integer', 'children': [], 'value': '2'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_write_json'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146', '147', '148']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '146', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '149', 'type': 'return_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '159', 'type': 'except_clause', 'children': ['160', '164']},{'id': '160', 'type': 'as_pattern', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'EnvironmentError'},{'id': '162', 'type': 'as_pattern_target', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '164', 'type': 'block', 'children': ['165', '179']},{'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': 'logger'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': '"Error while opening or writing to file: {}"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '179', 'type': 'raise_statement', 'children': []},{'id': '180', 'type': 'except_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'raise_statement', 'children': []} | def write_file(self, content, filepath=None, filename=None, indent=None, keys_to_write=None):
'''
Write a Python dictionary as JSON to a file.
:param content: Dictionary of key-value pairs to save to a file
:param filepath: Path where the file is to be created
:param filename: Name of the file to be created
:param indent: You can use this to specify indent level for pretty printing the file
:param keys_to_write: array of keys that are to be picked from data and written to file.
Default is None, when all data is written to file.
:return: Path of file used
:raises OSError, EnvironmentError, ValueError
'''
path = filepath if filepath else self.filepath
name = filename if filename else self.filename
if not os.path.exists(path):
try:
os.makedirs(path)
except OSError as error:
self.logger.error("Error while creating directory: {}".format(error))
raise
name = self._ends_with(name, ".json")
path = self._ends_with(path, os.path.sep)
if keys_to_write:
data_to_write = {}
for key in keys_to_write:
data_to_write[key] = content[key]
else:
data_to_write = content
try:
indent = indent if indent else 2
self._write_json(path, name, 'w', data_to_write, indent)
return os.path.join(path, name)
except EnvironmentError as error:
self.logger.error("Error while opening or writing to file: {}".format(error))
raise
except ValueError:
raise |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '28', '37', '47', '61', '112', '137']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '22', 'type': 'conditional_expression', 'children': ['23', '24', '25'], 'value': 'if'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'conditional_expression', 'children': ['32', '33', '34'], 'value': 'if'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_ends_with'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '46', 'type': 'string', 'children': [], 'value': '".json"'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_ends_with'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '61', 'type': 'if_statement', 'children': ['62', '73']},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'try_statement', 'children': ['75', '87', '108']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'write_file'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84', '85', '86']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '87', 'type': 'except_clause', 'children': ['88', '92']},{'id': '88', 'type': 'as_pattern', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'EnvironmentError'},{'id': '90', 'type': 'as_pattern_target', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '92', 'type': 'block', 'children': ['93', '107']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'error'},{'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': '"Error while opening or writing to file: {}"'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '107', 'type': 'raise_statement', 'children': []},{'id': '108', 'type': 'except_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': []},{'id': '112', 'type': 'if_statement', 'children': ['113', '114', '131']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '114', 'type': 'block', 'children': ['115', '119']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '118', 'type': 'dictionary', 'children': []},{'id': '119', 'type': 'for_statement', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys_to_write'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'data_to_write'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '137', 'type': 'try_statement', 'children': ['138', '253', '274']},{'id': '138', 'type': 'block', 'children': ['139', '211', '224', '232', '243']},{'id': '139', 'type': 'with_statement', 'children': ['140', '152']},{'id': '140', 'type': 'with_clause', 'children': ['141']},{'id': '141', 'type': 'with_item', 'children': ['142']},{'id': '142', 'type': 'as_pattern', 'children': ['143', '150']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '150', 'type': 'as_pattern_target', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'fil'},{'id': '152', 'type': 'block', 'children': ['153', '162', '176']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'fil'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'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': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': '"Read contents of {}"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '176', 'type': 'for_statement', 'children': ['177', '178', '179']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'try_statement', 'children': ['181', '190']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'except_clause', 'children': ['191', '195']},{'id': '191', 'type': 'as_pattern', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '193', 'type': 'as_pattern_target', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '195', 'type': 'block', 'children': ['196', '210']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '"File contents could not be serialized into a dict. {}"'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '210', 'type': 'raise_statement', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_write_json'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218', '221', '222', '223']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '220', 'type': 'string', 'children': [], 'value': '".temp"'},{'id': '221', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'indent'},{'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': 'FileUtils'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'remove_file'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'FileUtils'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'rename_file'},{'id': '237', 'type': 'argument_list', 'children': ['238', '241', '242']},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '+'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '240', 'type': 'string', 'children': [], 'value': "'.temp'"},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '243', 'type': 'return_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '250']},{'id': '245', 'type': 'attribute', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '253', 'type': 'except_clause', 'children': ['254', '258']},{'id': '254', 'type': 'as_pattern', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'EnvironmentError'},{'id': '256', 'type': 'as_pattern_target', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '258', 'type': 'block', 'children': ['259', '273']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'string', 'children': [], 'value': '"Error while writing to, opening or reading the file: {}"'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '273', 'type': 'raise_statement', 'children': []},{'id': '274', 'type': 'except_clause', 'children': ['275', '279']},{'id': '275', 'type': 'as_pattern', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '277', 'type': 'as_pattern_target', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '279', 'type': 'block', 'children': ['280', '294']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'string', 'children': [], 'value': '"File could not be decoded to JSON. It might be empty? {}"'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '294', 'type': 'try_statement', 'children': ['295', '317']},{'id': '295', 'type': 'block', 'children': ['296', '307']},{'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': 'self'},{'id': '300', 'type': 'identifier', 'children': [], 'value': '_write_json'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304', '305', '306']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '304', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'data_to_write'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '307', 'type': 'return_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '314']},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '317', 'type': 'except_clause', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'EnvironmentError'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'raise_statement', 'children': []} | def write_values(self, data, filepath=None, filename=None, indent=None, keys_to_write=None):
name = filename if filename else self.filename
path = filepath if filepath else self.filepath
name = self._ends_with(name, ".json")
path = self._ends_with(path, os.path.sep)
if not os.path.isfile(path + name):
try:
return self.write_file(data, path, name, indent, keys_to_write)
except EnvironmentError as error:
self.logger.error("Error while opening or writing to file: {}".format(error))
raise
except ValueError:
raise
if keys_to_write:
data_to_write = {}
for key in keys_to_write:
data_to_write[key] = data[key]
else:
data_to_write = data
try:
with open(path + name, 'r') as fil:
output = json.load(fil)
self.logger.info("Read contents of {}".format(filename))
for key in data_to_write:
try:
output[key] = data_to_write[key]
except TypeError as error:
self.logger.error(
"File contents could not be serialized into a dict. {}".format(error))
raise
self._write_json(path, name + ".temp", "w", output, indent)
FileUtils.remove_file(name, path)
FileUtils.rename_file(name + '.temp', name, path)
return os.path.join(path, name)
except EnvironmentError as error:
self.logger.error(
"Error while writing to, opening or reading the file: {}".format(error))
raise
except ValueError as error:
self.logger.error(
"File could not be decoded to JSON. It might be empty? {}".format(error))
try:
self._write_json(path, name, "w", data_to_write, indent)
return os.path.join(path, name)
except EnvironmentError:
raise |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_resolve_requirements'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '6', 'type': 'block', 'children': ['7', '24', '37', '48', '52', '63', '73', '84', '186', '246', '252']},{'id': '7', 'type': 'try_statement', 'children': ['8', '19']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dut_count'},{'id': '12', 'type': 'subscript', 'children': ['13', '18']},{'id': '13', 'type': 'subscript', 'children': ['14', '17']},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '16', 'type': 'string', 'children': [], 'value': '"duts"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '18', 'type': 'string', 'children': [], 'value': '"count"'},{'id': '19', 'type': 'except_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '27', 'type': 'dictionary', 'children': ['28', '31', '34']},{'id': '28', 'type': 'pair', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '30', 'type': 'string', 'children': [], 'value': '"hardware"'},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"allowed_platforms"'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'pair', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': '"nick"'},{'id': '36', 'type': 'None', 'children': []},{'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': 'default_values'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '46', 'type': 'string', 'children': [], 'value': '"duts"'},{'id': '47', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '48', 'type': 'delete_statement', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '51', 'type': 'string', 'children': [], 'value': '"count"'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dut_keys'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'},{'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': 'dut_keys'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'list', 'children': ['70', '71', '72'], 'value': '["application", "location", "subtype"]'},{'id': '70', 'type': 'string', 'children': [], 'value': '"application"'},{'id': '71', 'type': 'string', 'children': [], 'value': '"location"'},{'id': '72', 'type': 'string', 'children': [], 'value': '"subtype"'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '__generate_indexed_requirements'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dut_count'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'default_values'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '93']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'requirements'},{'id': '90', 'type': 'string', 'children': [], 'value': '"duts"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'block', 'children': ['94', '103', '113']},{'id': '94', 'type': 'if_statement', 'children': ['95', '101']},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'continue_statement', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "r'([\\d]{1,})\\.\\.([\\d]{1,})'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '113', 'type': 'if_statement', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '115', 'type': 'block', 'children': ['116', '128', '140']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'first_dut_idx'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'last_dut_idx'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'integer', 'children': [], 'value': '2'},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '149']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'first_dut_idx'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'last_dut_idx'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'dut_keys'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '162']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '157', 'type': 'subscript', 'children': ['158', '161']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '160', 'type': 'string', 'children': [], 'value': '"duts"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '172']},{'id': '165', 'type': 'attribute', 'children': ['166', '171']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '-'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'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': 'copy'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'subscript', 'children': ['180', '185']},{'id': '180', 'type': 'subscript', 'children': ['181', '184']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'requirements'},{'id': '183', 'type': 'string', 'children': [], 'value': '"duts"'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '186', 'type': 'for_statement', 'children': ['187', '190', '194']},{'id': '187', 'type': 'pattern_list', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '194', 'type': 'block', 'children': ['195', '234']},{'id': '195', 'type': 'if_statement', 'children': ['196', '206']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '198', 'type': 'argument_list', 'children': ['199', '205']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'string', 'children': [], 'value': '"nick"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '206', 'type': 'block', 'children': ['207', '216']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'string', 'children': [], 'value': '"nick"'},{'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': 'req'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': '"nick"'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ResourceConfig'},{'id': '226', 'type': 'identifier', 'children': [], 'value': '__replace_base_variables'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229', '233']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'nick'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'idx'},{'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': 'self'},{'id': '238', 'type': 'identifier', 'children': [], 'value': '_solve_location'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241', '245']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': '_dut_requirements'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'dut_requirements'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'None', 'children': []} | def _resolve_requirements(self, requirements):
try:
dut_count = requirements["duts"]["*"]["count"]
except KeyError:
return []
default_values = {
"type": "hardware",
"allowed_platforms": [],
"nick": None,
}
default_values.update(requirements["duts"]["*"])
del default_values["count"]
dut_keys = list(default_values.keys())
dut_keys.extend(["application", "location", "subtype"])
dut_requirements = self.__generate_indexed_requirements(dut_count,
default_values,
requirements)
for key in requirements["duts"].keys():
if not isinstance(key, string_types):
continue
match = re.search(r'([\d]{1,})\.\.([\d]{1,})', key)
if match:
first_dut_idx = int(match.group(1))
last_dut_idx = int(match.group(2))
for i in range(first_dut_idx, last_dut_idx+1):
for k in dut_keys:
if k in requirements["duts"][key]:
dut_requirements[i-1].set(k, copy.copy(requirements["duts"][key][k]))
for idx, req in enumerate(dut_requirements):
if isinstance(req.get("nick"), string_types):
nick = req.get("nick")
req.set("nick", ResourceConfig.__replace_base_variables(nick,
len(dut_requirements),
idx))
self._solve_location(req, len(dut_requirements), idx)
self._dut_requirements = dut_requirements
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'flash'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'binary_location'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'forceflash'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '30', '74', '96', '104', '113', '130', '271', '290', '298']},{'id': '12', 'type': 'if_statement', 'children': ['13', '15']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Flash'},{'id': '15', 'type': 'block', 'children': ['16', '25']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"Mbed-flasher not installed!"'},{'id': '25', 'type': 'raise_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': '"Mbed-flasher not installed!"'},{'id': '30', 'type': 'try_statement', 'children': ['31', '43']},{'id': '31', 'type': 'block', 'children': ['32']},{'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': 'build'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Build'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'init'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'binary_location'},{'id': '43', 'type': 'except_clause', 'children': ['44', '48']},{'id': '44', 'type': 'as_pattern', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '46', 'type': 'as_pattern_target', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '48', 'type': 'block', 'children': ['49', '60', '69']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'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': 'logger'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'concatenated_string', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"Build initialization failed. "'},{'id': '59', 'type': 'string', 'children': [], 'value': '"Check your build location."'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '69', 'type': 'raise_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'DutConnectionError'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '74', 'type': 'if_statement', 'children': ['75', '84']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_flash_needed'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'forceflash'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'forceflash'},{'id': '84', 'type': 'block', 'children': ['85', '94']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"Skipping flash, not needed."'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'True', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_external_logger'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"mbed-flasher"'},{'id': '103', 'type': 'string', 'children': [], 'value': '"FLS"'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'flasher'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'Flash'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'logger'},{'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': 'device'},{'id': '118', 'type': 'block', 'children': ['119', '128']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': '"Trying to flash device but device is not there?"'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'False', 'children': []},{'id': '130', 'type': 'try_statement', 'children': ['131', '201']},{'id': '131', 'type': 'block', 'children': ['132', '142', '156', '170', '181']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'buildfile'},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'get_file'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '145']},{'id': '143', 'type': 'not_operator', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'buildfile'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'raise_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'DutConnectionError'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': '"Binary {} not found"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'buildfile'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "'Flashing dev: %s'"},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '169', 'type': 'string', 'children': [], 'value': "'target_id'"},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'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': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': '"target_id"'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'flasher'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'flash'},{'id': '188', 'type': 'argument_list', 'children': ['189', '192', '195']},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'buildfile'},{'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'target_id'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'device_mapping_table'},{'id': '197', 'type': 'list', 'children': ['198'], 'value': '[self.device]'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '201', 'type': 'except_clause', 'children': ['202', '206']},{'id': '202', 'type': 'as_pattern', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'FLASHER_ERRORS'},{'id': '204', 'type': 'as_pattern_target', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '206', 'type': 'block', 'children': ['207', '239', '266']},{'id': '207', 'type': 'if_statement', 'children': ['208', '213', '223']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': '=='},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '221']},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': '"Flashing not supported for this platform!"'},{'id': '223', 'type': 'elif_clause', 'children': ['224', '229']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '228'], 'value': '=='},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '237']},{'id': '232', 'type': 'attribute', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'string', 'children': [], 'value': '"target_id required by mbed-flasher!"'},{'id': '239', 'type': 'if_statement', 'children': ['240', '243']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'FlashError'},{'id': '242', 'type': 'None', 'children': []},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'if_statement', 'children': ['245', '250']},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '249'], 'value': '=='},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '248', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'FlashError'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '258']},{'id': '253', 'type': 'attribute', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260', '263']},{'id': '259', 'type': 'string', 'children': [], 'value': '"Flasher raised the following error: %s Error code: %i"'},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'return_code'},{'id': '266', 'type': 'raise_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'DutConnectionError'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '271', 'type': 'if_statement', 'children': ['272', '275']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': '=='},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'block', 'children': ['276', '288']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'dutinformation'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'build_binary_sha1'},{'id': '283', 'type': 'attribute', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'True', 'children': []},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'dutinformation'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'build_binary_sha1'},{'id': '297', 'type': 'None', 'children': []},{'id': '298', 'type': 'return_statement', 'children': ['299']},{'id': '299', 'type': 'False', 'children': []} | def flash(self, binary_location=None, forceflash=None):
if not Flash:
self.logger.error("Mbed-flasher not installed!")
raise ImportError("Mbed-flasher not installed!")
try:
self.build = Build.init(binary_location)
except NotImplementedError as error:
self.logger.error("Build initialization failed. "
"Check your build location.")
self.logger.debug(error)
raise DutConnectionError(error)
if not self._flash_needed(forceflash=forceflash):
self.logger.info("Skipping flash, not needed.")
return True
logger = get_external_logger("mbed-flasher", "FLS")
flasher = Flash(logger=logger)
if not self.device:
self.logger.error("Trying to flash device but device is not there?")
return False
try:
buildfile = self.build.get_file()
if not buildfile:
raise DutConnectionError("Binary {} not found".format(buildfile))
self.logger.info('Flashing dev: %s', self.device['target_id'])
target_id = self.device.get("target_id")
retcode = flasher.flash(build=buildfile, target_id=target_id,
device_mapping_table=[self.device])
except FLASHER_ERRORS as error:
if error.__class__ == NotImplementedError:
self.logger.error("Flashing not supported for this platform!")
elif error.__class__ == SyntaxError:
self.logger.error("target_id required by mbed-flasher!")
if FlashError is not None:
if error.__class__ == FlashError:
self.logger.error("Flasher raised the following error: %s Error code: %i",
error.message, error.return_code)
raise DutConnectionError(error)
if retcode == 0:
self.dutinformation.build_binary_sha1 = self.build.sha1
return True
self.dutinformation.build_binary_sha1 = None
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'open_connection'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '46', '64', '82', '197', '251', '264', '282']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'readthread'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'raise_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DutConnectionError'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Trying to open serial port which was already open"'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '25', 'type': 'argument_list', 'children': ['26', '40']},{'id': '26', 'type': 'binary_operator', 'children': ['27', '30'], 'value': '%'},{'id': '27', 'type': 'concatenated_string', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': '"Open Connection "'},{'id': '29', 'type': 'string', 'children': [], 'value': '"for \'%s\' using \'%s\' baudrate: %d"'},{'id': '30', 'type': 'tuple', 'children': ['31', '34', '37']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dut_name'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'comport'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'serial_baudrate'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '42', 'type': 'dictionary', 'children': ['43']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'<->'"},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'serial_xonxoff'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '%'},{'id': '60', 'type': 'string', 'children': [], 'value': '"Use software flow control for dut: %s"'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dut_name'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'serial_rtscts'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'},{'id': '78', 'type': 'string', 'children': [], 'value': '"Use hardware flow control for dut: %s"'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dut_name'},{'id': '82', 'type': 'try_statement', 'children': ['83', '151', '174']},{'id': '83', 'type': 'block', 'children': ['84', '95', '105', '115', '125', '135', '143']},{'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': 'port'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'EnhancedSerial'},{'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': 'comport'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '102']},{'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': 'port'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'baudrate'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'serial_baudrate'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', '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': 'port'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'serial_timeout'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', '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': 'port'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'xonxoff'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'serial_xonxoff'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '132']},{'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': 'port'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'rtscts'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'serial_rtscts'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'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': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'flushInput'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'flushOutput'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'except_clause', 'children': ['152', '156']},{'id': '152', 'type': 'as_pattern', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'SerialException'},{'id': '154', 'type': 'as_pattern_target', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '156', 'type': 'block', 'children': ['157', '166']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '166', 'type': 'raise_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'DutConnectionError'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '174', 'type': 'except_clause', 'children': ['175', '179']},{'id': '175', 'type': 'as_pattern', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '177', 'type': 'as_pattern_target', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '179', 'type': 'block', 'children': ['180', '189']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'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': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '189', 'type': 'raise_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201', '234']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'ch_mode'},{'id': '201', 'type': 'block', 'children': ['202', '225']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '209', 'type': 'argument_list', 'children': ['210', '219']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '%'},{'id': '211', 'type': 'string', 'children': [], 'value': '"Use chunk-mode with size %d, delay: %.3f when write data"'},{'id': '212', 'type': 'tuple', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ch_mode_chunk_size'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'ch_mode_ch_delay'},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '221', 'type': 'dictionary', 'children': ['222']},{'id': '222', 'type': 'pair', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '224', 'type': 'string', 'children': [], 'value': "'<->'"},{'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': 'time'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ch_mode_start_delay'},{'id': '234', 'type': 'else_clause', 'children': ['235']},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '243']},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245']},{'id': '244', 'type': 'string', 'children': [], 'value': '"Use normal serial write mode"'},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '247', 'type': 'dictionary', 'children': ['248']},{'id': '248', 'type': 'pair', 'children': ['249', '250']},{'id': '249', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '250', 'type': 'string', 'children': [], 'value': "'<->'"},{'id': '251', 'type': 'if_statement', 'children': ['252', '257']},{'id': '252', 'type': 'attribute', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '257', 'type': 'block', 'children': ['258']},{'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': 'self'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '263', 'type': 'argument_list', 'children': []},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'readthread'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'Thread'},{'id': '271', 'type': 'argument_list', 'children': ['272', '277']},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'run'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '289']},{'id': '284', 'type': 'attribute', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'readthread'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '289', 'type': 'argument_list', 'children': []} | def open_connection(self):
if self.readthread is not None:
raise DutConnectionError("Trying to open serial port which was already open")
self.logger.info("Open Connection "
"for '%s' using '%s' baudrate: %d" % (self.dut_name,
self.comport,
self.serial_baudrate),
extra={'type': '<->'})
if self.serial_xonxoff:
self.logger.debug("Use software flow control for dut: %s" % self.dut_name)
if self.serial_rtscts:
self.logger.debug("Use hardware flow control for dut: %s" % self.dut_name)
try:
self.port = EnhancedSerial(self.comport)
self.port.baudrate = self.serial_baudrate
self.port.timeout = self.serial_timeout
self.port.xonxoff = self.serial_xonxoff
self.port.rtscts = self.serial_rtscts
self.port.flushInput()
self.port.flushOutput()
except SerialException as err:
self.logger.warning(err)
raise DutConnectionError(str(err))
except ValueError as err:
self.logger.warning(err)
raise ValueError(str(err))
if self.ch_mode:
self.logger.info("Use chunk-mode with size %d, delay: %.3f when write data" %
(self.ch_mode_chunk_size, self.ch_mode_ch_delay),
extra={'type': '<->'})
time.sleep(self.ch_mode_start_delay)
else:
self.logger.info("Use normal serial write mode", extra={'type': '<->'})
if self.params.reset:
self.reset()
self.readthread = Thread(name=self.name, target=self.run)
self.readthread.start() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_info'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '23', '27', '31', '49', '71', '188', '222', '231', '240', '247']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'PrettyTable'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'start_string'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': '"DutSerial {} \\n"'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'info_string'},{'id': '30', 'type': 'string', 'children': [], 'value': '""'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'},{'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': 'info_string'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'info_string'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': '"Configuration for this DUT:\\n\\n {} \\n"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'comport'},{'id': '53', 'type': 'block', 'children': ['54', '62']},{'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': 'table'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': '"COM port"'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'row'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'comport'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '75', 'type': 'block', 'children': ['76', '104', '132', '160']},{'id': '76', 'type': 'if_statement', 'children': ['77', '84']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '83', 'type': 'string', 'children': [], 'value': '"baudrate"'},{'id': '84', 'type': 'block', 'children': ['85', '93']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '"Baudrate"'},{'id': '92', 'type': 'list', 'children': [], 'value': '[]'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'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': 'port'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'baudrate'},{'id': '104', 'type': 'if_statement', 'children': ['105', '112']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '111', 'type': 'string', 'children': [], 'value': '"xonxoff"'},{'id': '112', 'type': 'block', 'children': ['113', '121']},{'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': 'table'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"XON/XOFF"'},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'row'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'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': 'port'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'xonxoff'},{'id': '132', 'type': 'if_statement', 'children': ['133', '140']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '135', 'type': 'argument_list', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '139', 'type': 'string', 'children': [], 'value': '"timeout"'},{'id': '140', 'type': 'block', 'children': ['141', '149']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': '"Timeout"'},{'id': '148', 'type': 'list', 'children': [], 'value': '[]'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '160', 'type': 'if_statement', 'children': ['161', '168']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '163', 'type': 'argument_list', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '167', 'type': 'string', 'children': [], 'value': '"rtscts"'},{'id': '168', 'type': 'block', 'children': ['169', '177']},{'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': 'table'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'string', 'children': [], 'value': '"RTSCTS"'},{'id': '176', 'type': 'list', 'children': [], 'value': '[]'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'rtscts'},{'id': '188', 'type': 'if_statement', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '192', 'type': 'block', 'children': ['193', '201']},{'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': 'table'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'add_column'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': '"Location"'},{'id': '200', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'row'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'},{'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': '"X = {}, Y = {}"'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '211', 'type': 'argument_list', 'children': ['212', '217']},{'id': '212', 'type': 'attribute', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'x_coord'},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'y_coord'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'start_string'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '238']},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'info_string'},{'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': 'table'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'add_row'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'table'} | def print_info(self):
table = PrettyTable()
start_string = "DutSerial {} \n".format(self.name)
row = []
info_string = ""
if self.config:
info_string = info_string + "Configuration for this DUT:\n\n {} \n".format(self.config)
if self.comport:
table.add_column("COM port", [])
row.append(self.comport)
if self.port:
if hasattr(self.port, "baudrate"):
table.add_column("Baudrate", [])
row.append(self.port.baudrate)
if hasattr(self.port, "xonxoff"):
table.add_column("XON/XOFF", [])
row.append(self.port.xonxoff)
if hasattr(self.port, "timeout"):
table.add_column("Timeout", [])
row.append(self.port.timeout)
if hasattr(self.port, "rtscts"):
table.add_column("RTSCTS", [])
row.append(self.port.rtscts)
if self.location:
table.add_column("Location", [])
row.append("X = {}, Y = {}".format(self.location.x_coord, self.location.y_coord))
self.logger.info(start_string)
self.logger.debug(info_string)
table.add_row(row)
print(table) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '5', 'type': 'block', 'children': ['6', '19', '31', '53', '61', '73', '93', '130']},{'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': 'labels'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'labels are not in a list'"},{'id': '19', 'type': 'if_statement', 'children': ['20', '25']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'the labels list is empty'"},{'id': '31', 'type': 'if_statement', 'children': ['32', '47']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '44']},{'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': 'l'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'all labels must be numpy arrays'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '61', 'type': 'if_statement', 'children': ['62', '67']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'not'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': '[1, 2]'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'integer', 'children': [], 'value': '2'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'raise_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'labels dimension must be 1 or 2'"},{'id': '73', 'type': 'if_statement', 'children': ['74', '87']},{'id': '74', 'type': 'not_operator', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'list_comprehension', 'children': ['79', '84']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': '=='},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'all labels dimensions must be equal'"},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '96', 'type': 'integer', 'children': [], 'value': '2'},{'id': '97', 'type': 'block', 'children': ['98', '108']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'shape1'},{'id': '101', 'type': 'subscript', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'if_statement', 'children': ['109', '124']},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'list_comprehension', 'children': ['114', '121']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '120'], 'value': '=='},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'shape1'},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'raise_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'all labels must have same shape on 2nd dim'"},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '133', 'type': 'block', 'children': ['134', '158', '169']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '137', 'type': '()', 'children': ['138']},{'id': '138', 'type': 'conditional_expression', 'children': ['139', '145', '150'], 'value': 'if'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '=='},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'lexsort'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '158', 'type': 'assert_statement', 'children': ['159']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': '=='},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'if_statement', 'children': ['170', '191']},{'id': '170', 'type': 'not_operator', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '173', 'type': 'generator_expression', 'children': ['174', '179']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': '=='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'binary_operator', 'children': ['185', '190'], 'value': '-'},{'id': '185', 'type': 'subscript', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'raise_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'string', 'children': [], 'value': "'labels are not sorted in increasing order'"} | def check(labels):
if not isinstance(labels, list):
raise IOError('labels are not in a list')
if not len(labels):
raise IOError('the labels list is empty')
if not all([isinstance(l, np.ndarray) for l in labels]):
raise IOError('all labels must be numpy arrays')
ndim = labels[0].ndim
if ndim not in [1, 2]:
raise IOError('labels dimension must be 1 or 2')
if not all([l.ndim == ndim for l in labels]):
raise IOError('all labels dimensions must be equal')
if ndim == 2:
shape1 = labels[0].shape[1]
if not all([l.shape[1] == shape1 for l in labels]):
raise IOError('all labels must have same shape on 2nd dim')
for label in labels:
index = (np.argsort(label) if label.ndim == 1
else np.lexsort(label.T))
assert len(index) == label.shape[0]
if not all(n == index[n] for n in range(label.shape[0]-1)):
raise IOError('labels are not sorted in increasing order') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'times'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dformat'},{'id': '14', 'type': 'string', 'children': [], 'value': "'dense'"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '17', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sparsity'},{'id': '20', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '23', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '24', 'type': 'block', 'children': ['25', '34', '52']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sparsity'},{'id': '28', 'type': 'conditional_expression', 'children': ['29', '30', '33'], 'value': 'if'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sparsity'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dformat'},{'id': '32', 'type': 'string', 'children': [], 'value': "'sparse'"},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'Data'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '43', '46', '49']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'times'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sparsity'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sparsity'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '63']},{'id': '54', 'type': 'attribute', 'children': ['55', '62']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Writer'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'True', 'children': []} | def write(filename, groupname, items, times, features, properties=None,
dformat='dense', chunk_size='auto', sparsity=0.1, mode='a'):
sparsity = sparsity if dformat == 'sparse' else None
data = Data(items, times, features, properties=properties,
sparsity=sparsity, check=True)
Writer(filename, chunk_size=chunk_size).write(data, groupname, append=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'to_item'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'from_time'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'to_time'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '39', '54', '71', '84', '97', '106', '115', '125', '137', '197', '257', '272', '298']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'to_item'},{'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': 'to_item'},{'id': '26', 'type': 'conditional_expression', 'children': ['27', '35', '38'], 'value': 'if'},{'id': '27', 'type': 'subscript', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '42', 'type': 'None', 'children': []},{'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': 'from_item'},{'id': '47', 'type': 'subscript', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'if_statement', 'children': ['55', '65']},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'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': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'is_valid_interval'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'to_item'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': "'cannot read items: not a valid interval'"},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '74', 'type': 'call', 'children': ['75', '82']},{'id': '75', 'type': 'attribute', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'from_item'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '87', 'type': 'call', 'children': ['88', '95']},{'id': '88', 'type': 'attribute', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'to_item'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'from_pos'},{'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': '_get_item_position'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'to_pos'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_get_item_position'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'lower'},{'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': '_get_from_time'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'from_time'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'from_pos'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '136'], 'value': '+'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_get_to_time'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'to_time'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'to_pos'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'if_statement', 'children': ['138', '143', '149']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '=='},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'dformat'},{'id': '142', 'type': 'string', 'children': [], 'value': "'sparse'"},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'raise_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': "'Reading sparse features not implemented'"},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151', '186']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '154', 'type': '()', 'children': ['155']},{'id': '155', 'type': 'conditional_expression', 'children': ['156', '170', '175'], 'value': 'if'},{'id': '156', 'type': 'attribute', 'children': ['157', '169']},{'id': '157', 'type': 'subscript', 'children': ['158', '163', '165']},{'id': '158', 'type': 'subscript', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '162', 'type': 'string', 'children': [], 'value': "'features'"},{'id': '163', 'type': 'slice', 'children': ['164']},{'id': '164', 'type': 'colon', 'children': []},{'id': '165', 'type': 'slice', 'children': ['166', '167', '168']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '167', 'type': 'colon', 'children': []},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '174', 'type': 'string', 'children': [], 'value': "'0.1'"},{'id': '175', 'type': 'subscript', 'children': ['176', '181', '185']},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '180', 'type': 'string', 'children': [], 'value': "'features'"},{'id': '181', 'type': 'slice', 'children': ['182', '183', '184']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '183', 'type': 'colon', 'children': []},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '185', 'type': 'ellipsis', 'children': [], 'value': '...'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '189', 'type': 'subscript', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': '_labels_group'},{'id': '193', 'type': 'slice', 'children': ['194', '195', '196']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '195', 'type': 'colon', 'children': []},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201', '212']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '=='},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '201', 'type': 'block', 'children': ['202', '207']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '205', 'type': 'list', 'children': ['206'], 'value': '[features]'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '210', 'type': 'list', 'children': ['211'], 'value': '[labels]'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '212', 'type': 'else_clause', 'children': ['213']},{'id': '213', 'type': 'block', 'children': ['214', '231', '244']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'item_ends'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '230'], 'value': '+'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '227'], 'value': '-'},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '223', 'type': 'slice', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '225', 'type': 'colon', 'children': []},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'from_pos'},{'id': '229', 'type': 'integer', 'children': [], 'value': '0'},{'id': '230', 'type': 'integer', 'children': [], 'value': '1'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240', '241']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'item_ends'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '243', 'type': 'integer', 'children': [], 'value': '0'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253', '254']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'item_ends'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '256', 'type': 'integer', 'children': [], 'value': '0'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '260', 'type': 'subscript', 'children': ['261', '266']},{'id': '261', 'type': 'attribute', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '266', 'type': 'slice', 'children': ['267', '268', '269']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '268', 'type': 'colon', 'children': []},{'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '+'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'if_statement', 'children': ['273', '278', '283']},{'id': '273', 'type': 'comparison_operator', 'children': ['274', '277'], 'value': 'is'},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '277', 'type': 'None', 'children': []},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '282', 'type': 'None', 'children': []},{'id': '283', 'type': 'else_clause', 'children': ['284']},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '292', 'type': 'slice', 'children': ['293', '294', '295']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'from_idx'},{'id': '294', 'type': 'colon', 'children': []},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '+'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'to_idx'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'return_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'Data'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304', '305', '308']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '310', 'type': 'False', 'children': []} | def read(self, from_item=None, to_item=None,
from_time=None, to_time=None):
if to_item is None:
to_item = self.items.data[-1] if from_item is None else from_item
if from_item is None:
from_item = self.items.data[0]
if not self.items.is_valid_interval(from_item, to_item):
raise IOError('cannot read items: not a valid interval')
from_idx = self.items.data.index(from_item)
to_idx = self.items.data.index(to_item)
from_pos = self._get_item_position(from_idx)
to_pos = self._get_item_position(to_idx)
lower = self._get_from_time(from_time, from_pos)
upper = self._get_to_time(to_time, to_pos) + 1
if self.dformat == 'sparse':
raise NotImplementedError(
'Reading sparse features not implemented')
else:
features = (self.group['features'][:, lower:upper].T
if self.version == '0.1'
else self.group['features'][lower:upper, ...])
labels = self._labels_group[lower:upper]
if to_idx == from_idx:
features = [features]
labels = [labels]
else:
item_ends = self._index[from_idx:to_idx] - from_pos[0] + 1
features = np.split(features, item_ends, axis=0)
labels = np.split(labels, item_ends, axis=0)
items = self.items.data[from_idx:to_idx + 1]
if self.properties is None:
properties = None
else:
properties = self.properties[from_idx:to_idx + 1]
return Data(
items, labels, features, properties=properties, check=False) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '5', 'type': 'block', 'children': ['6', '32', '48', '373']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '11', 'type': 'argument_list', 'children': ['12', '15', '18', '21', '24', '27']},{'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ninputs'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'noutputs'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'input_labels'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'output_labels'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'intype'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cover'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '41']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '52', '59']},{'id': '49', 'type': 'pattern_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'block', 'children': ['60', '72', '81', '113', '122', '154', '163', '167', '176', '209', '218', '251', '260', '291', '300', '349', '358', '362']},{'id': '60', 'type': 'if_statement', 'children': ['61', '70']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '64'], 'value': 'or'},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_COMMENT'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'continue_statement', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'm_in'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_NINS'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '81', 'type': 'if_statement', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'm_in'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '90', '106']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': 'is'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '88', 'type': 'string', 'children': [], 'value': "'ninputs'"},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '105']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '95', 'type': 'string', 'children': [], 'value': "'ninputs'"},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'm_in'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'continue_statement', 'children': []},{'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': 'Error'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '".i declared more than once"'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'm_out'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_NOUTS'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '122', 'type': 'if_statement', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'm_out'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '131', '147']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': 'is'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '129', 'type': 'string', 'children': [], 'value': "'noutputs'"},{'id': '130', 'type': 'None', 'children': []},{'id': '131', 'type': 'block', 'children': ['132', '146']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '136', 'type': 'string', 'children': [], 'value': "'noutputs'"},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'm_out'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'continue_statement', 'children': []},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'raise_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': '".o declared more than once"'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'm_prod'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': '_PROD'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '163', 'type': 'if_statement', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'm_prod'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'continue_statement', 'children': []},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'm_ilb'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': '_ILB'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '176', 'type': 'if_statement', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'm_ilb'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'if_statement', 'children': ['180', '185', '202']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '184'], 'value': 'is'},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '183', 'type': 'string', 'children': [], 'value': "'input_labels'"},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'block', 'children': ['186', '201']},{'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': 'd'},{'id': '190', 'type': 'string', 'children': [], 'value': "'input_labels'"},{'id': '191', 'type': 'call', 'children': ['192', '200']},{'id': '192', 'type': 'attribute', 'children': ['193', '199']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'm_ilb'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'continue_statement', 'children': []},{'id': '202', 'type': 'else_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'raise_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'string', 'children': [], 'value': '".ilb declared more than once"'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'm_ob'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_OB'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '218', 'type': 'if_statement', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'm_ob'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'if_statement', 'children': ['222', '227', '244']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': 'is'},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '225', 'type': 'string', 'children': [], 'value': "'output_labels'"},{'id': '226', 'type': 'None', 'children': []},{'id': '227', 'type': 'block', 'children': ['228', '243']},{'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': 'd'},{'id': '232', 'type': 'string', 'children': [], 'value': "'output_labels'"},{'id': '233', 'type': 'call', 'children': ['234', '242']},{'id': '234', 'type': 'attribute', 'children': ['235', '241']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'm_ob'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'integer', 'children': [], 'value': '1'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'continue_statement', 'children': []},{'id': '244', 'type': 'else_clause', 'children': ['245']},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'raise_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'string', 'children': [], 'value': '".ob declared more than once"'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'm_type'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_TYPE'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '260', 'type': 'if_statement', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'm_type'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'if_statement', 'children': ['264', '269', '284']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '268'], 'value': 'is'},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '267', 'type': 'string', 'children': [], 'value': "'intype'"},{'id': '268', 'type': 'None', 'children': []},{'id': '269', 'type': 'block', 'children': ['270', '283']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '275']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '274', 'type': 'string', 'children': [], 'value': "'intype'"},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': '_TYPES'},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'm_type'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'integer', 'children': [], 'value': '1'},{'id': '283', 'type': 'continue_statement', 'children': []},{'id': '284', 'type': 'else_clause', 'children': ['285']},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'raise_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'string', 'children': [], 'value': '".type declared more tha once"'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'm_cube'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': '_CUBE'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '300', 'type': 'if_statement', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'm_cube'},{'id': '302', 'type': 'block', 'children': ['303', '313', '325', '337', '348']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '308']},{'id': '305', 'type': 'pattern_list', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'm_cube'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'invec'},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '318', 'type': 'generator_expression', 'children': ['319', '322']},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': '_INCODE'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '322', 'type': 'for_in_clause', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'outvec'},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '330', 'type': 'generator_expression', 'children': ['331', '334']},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': '_OUTCODE'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '334', 'type': 'for_in_clause', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '344']},{'id': '339', 'type': 'attribute', 'children': ['340', '343']},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '342', 'type': 'string', 'children': [], 'value': "'cover'"},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'tuple', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'invec'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'outvec'},{'id': '348', 'type': 'continue_statement', 'children': []},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'm_end'},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': '_END'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '358', 'type': 'if_statement', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'm_end'},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'continue_statement', 'children': []},{'id': '362', 'type': 'raise_statement', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '365', 'type': 'argument_list', 'children': ['366']},{'id': '366', 'type': 'call', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'string', 'children': [], 'value': '"syntax error on line {}: {}"'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '370', 'type': 'argument_list', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '373', 'type': 'return_statement', 'children': ['374']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'd'} | def parse(s):
d = dict(ninputs=None, noutputs=None,
input_labels=None, output_labels=None,
intype=None, cover=set())
lines = [line.strip() for line in s.splitlines()]
for i, line in enumerate(lines, start=1):
if not line or _COMMENT.match(line):
continue
m_in = _NINS.match(line)
if m_in:
if d['ninputs'] is None:
d['ninputs'] = int(m_in.group(1))
continue
else:
raise Error(".i declared more than once")
m_out = _NOUTS.match(line)
if m_out:
if d['noutputs'] is None:
d['noutputs'] = int(m_out.group(1))
continue
else:
raise Error(".o declared more than once")
m_prod = _PROD.match(line)
if m_prod:
continue
m_ilb = _ILB.match(line)
if m_ilb:
if d['input_labels'] is None:
d['input_labels'] = m_ilb.group(1).split()
continue
else:
raise Error(".ilb declared more than once")
m_ob = _OB.match(line)
if m_ob:
if d['output_labels'] is None:
d['output_labels'] = m_ob.group(1).split()
continue
else:
raise Error(".ob declared more than once")
m_type = _TYPE.match(line)
if m_type:
if d['intype'] is None:
d['intype'] = _TYPES[m_type.group(1)]
continue
else:
raise Error(".type declared more tha once")
m_cube = _CUBE.match(line)
if m_cube:
inputs, outputs = m_cube.groups()
invec = tuple(_INCODE[c] for c in inputs)
outvec = tuple(_OUTCODE[c] for c in outputs)
d['cover'].add((invec, outvec))
continue
m_end = _END.match(line)
if m_end:
continue
raise Error("syntax error on line {}: {}".format(i, line))
return d |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'var'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '16', '51', '60', '90', '145', '194', '223']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '26', '35']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '24', 'type': 'tuple', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'elif_clause', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37', '41']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '40', 'type': 'string', 'children': [], 'value': '"expected name to be a str or tuple, got {0.__name__}"'},{'id': '41', 'type': 'raise_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '51', 'type': 'if_statement', 'children': ['52', '54']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"expected at least one name"'},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '63', 'type': 'block', 'children': ['64', '71']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '75', 'type': 'block', 'children': ['76', '80']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '79', 'type': 'string', 'children': [], 'value': '"expected name to be a str, got {0.__name__}"'},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': 'fstr'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'tname'},{'id': '90', 'type': 'if_statement', 'children': ['91', '94', '101']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103', '110']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '110', 'type': 'if_statement', 'children': ['111', '114', '120', '129']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '118', 'type': 'tuple', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '120', 'type': 'elif_clause', 'children': ['121', '124']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131', '135']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '134', 'type': 'string', 'children': [], 'value': '"expected index to be an int or tuple, got {0.__name__}"'},{'id': '135', 'type': 'raise_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '145', 'type': 'for_statement', 'children': ['146', '147', '148']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '148', 'type': 'block', 'children': ['149', '156', '175']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '156', 'type': 'if_statement', 'children': ['157', '160']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '160', 'type': 'block', 'children': ['161', '165']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '164', 'type': 'string', 'children': [], 'value': '"expected index to be an int, got {0.__name__}"'},{'id': '165', 'type': 'raise_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'tindex'},{'id': '175', 'type': 'if_statement', 'children': ['176', '179']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': '<'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'block', 'children': ['180', '184']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '183', 'type': 'string', 'children': [], 'value': '"expected index to be >= 0, got {}"'},{'id': '184', 'type': 'raise_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '194', 'type': 'try_statement', 'children': ['195', '204']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'VARIABLES'},{'id': '201', 'type': 'tuple', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '204', 'type': 'except_clause', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '206', 'type': 'block', 'children': ['207', '215']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'Variable'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '222']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'VARIABLES'},{'id': '219', 'type': 'tuple', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '223', 'type': 'return_statement', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'v'} | def var(name, index=None):
tname = type(name)
if tname is str:
names = (name, )
elif tname is tuple:
names = name
else:
fstr = "expected name to be a str or tuple, got {0.__name__}"
raise TypeError(fstr.format(tname))
if not names:
raise ValueError("expected at least one name")
for name in names:
tname = type(name)
if tname is not str:
fstr = "expected name to be a str, got {0.__name__}"
raise TypeError(fstr.format(tname))
if index is None:
indices = tuple()
else:
tindex = type(index)
if tindex is int:
indices = (index, )
elif tindex is tuple:
indices = index
else:
fstr = "expected index to be an int or tuple, got {0.__name__}"
raise TypeError(fstr.format(tindex))
for index in indices:
tindex = type(index)
if tindex is not int:
fstr = "expected index to be an int, got {0.__name__}"
raise TypeError(fstr.format(tindex))
if index < 0:
fstr = "expected index to be >= 0, got {}"
raise ValueError(fstr.format(index))
try:
v = VARIABLES[(names, indices)]
except KeyError:
v = Variable(names, indices)
VARIABLES[(names, indices)] = v
return v |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_itemize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '5', 'type': 'block', 'children': ['6', '21', '35']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15']},{'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': 'objs'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'raise_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"expected a sequence of Function"'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isseq'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '32']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '35', 'type': 'if_statement', 'children': ['36', '41', '122', '215']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isseq'},{'id': '41', 'type': 'block', 'children': ['42', '46', '108']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '95']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '61', '66', '77', '88']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'BinaryDecisionDiagram'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'BinaryDecisionDiagram'},{'id': '66', 'type': 'elif_clause', 'children': ['67', '72']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Expression'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Expression'},{'id': '77', 'type': 'elif_clause', 'children': ['78', '83']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'TruthTable'},{'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': 'ftype'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'TruthTable'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': '"expected valid Function inputs"'},{'id': '95', 'type': 'elif_clause', 'children': ['96', '102']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'raise_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': '"expected uniform Function types"'},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'expression_list', 'children': ['110', '114', '121']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '114', 'type': 'tuple', 'children': ['115']},{'id': '115', 'type': 'tuple', 'children': ['116', '117']},{'id': '116', 'type': 'integer', 'children': [], 'value': '0'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '122', 'type': 'elif_clause', 'children': ['123', '127']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'isseq'},{'id': '127', 'type': 'block', 'children': ['128', '134', '138', '142', '198', '210']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '141', 'type': 'None', 'children': []},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '145', 'type': 'block', 'children': ['146', '156', '175', '194']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '152']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_items'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '_shape'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_ftype'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_itemize'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '156', 'type': 'if_statement', 'children': ['157', '160', '165']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '159', 'type': 'None', 'children': []},{'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': 'shape'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_shape'},{'id': '165', 'type': 'elif_clause', 'children': ['166', '169']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '!='},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_shape'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'raise_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': '"expected uniform farray dimensions"'},{'id': '175', 'type': 'if_statement', 'children': ['176', '179', '184']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'is'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '178', 'type': 'None', 'children': []},{'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': 'ftype'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_ftype'},{'id': '184', 'type': 'elif_clause', 'children': ['185', '188']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '!='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '187', 'type': 'identifier', 'children': [], 'value': '_ftype'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'raise_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'string', 'children': [], 'value': '"expected uniform Function types"'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '197'], 'value': '+='},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_items'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '209'], 'value': '+'},{'id': '202', 'type': 'tuple', 'children': ['203']},{'id': '203', 'type': 'tuple', 'children': ['204', '205']},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'objs'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'expression_list', 'children': ['212', '213', '214']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '215', 'type': 'else_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'raise_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'string', 'children': [], 'value': '"expected uniform farray dimensions"'} | def _itemize(objs):
if not isinstance(objs, collections.Sequence):
raise TypeError("expected a sequence of Function")
isseq = [isinstance(obj, collections.Sequence) for obj in objs]
if not any(isseq):
ftype = None
for obj in objs:
if ftype is None:
if isinstance(obj, BinaryDecisionDiagram):
ftype = BinaryDecisionDiagram
elif isinstance(obj, Expression):
ftype = Expression
elif isinstance(obj, TruthTable):
ftype = TruthTable
else:
raise TypeError("expected valid Function inputs")
elif not isinstance(obj, ftype):
raise ValueError("expected uniform Function types")
return list(objs), ((0, len(objs)), ), ftype
elif all(isseq):
items = list()
shape = None
ftype = None
for obj in objs:
_items, _shape, _ftype = _itemize(obj)
if shape is None:
shape = _shape
elif shape != _shape:
raise ValueError("expected uniform farray dimensions")
if ftype is None:
ftype = _ftype
elif ftype != _ftype:
raise ValueError("expected uniform Function types")
items += _items
shape = ((0, len(objs)), ) + shape
return items, shape, ftype
else:
raise ValueError("expected uniform farray dimensions") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_filtdim'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '8', 'type': 'block', 'children': ['9', '23', '30', '36', '52', '61', '67', '341']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'normshape'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '14', 'type': 'generator_expression', 'children': ['15', '18']},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '-'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'nsl_type'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'newitems'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mul'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'normshape'},{'id': '47', 'type': 'slice', 'children': ['48', '49']},{'id': '48', 'type': 'colon', 'children': []},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '60'], 'value': '//'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'normshape'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71', '118', '200']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'nsl_type'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '71', 'type': 'block', 'children': ['72', '102']},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '78']},{'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': 'num'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'if_statement', 'children': ['80', '85']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '84'], 'value': '=='},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'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': 'newitems'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '91', 'type': 'slice', 'children': ['92', '95', '96']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '*'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '*'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '98', 'type': '()', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'newshape'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '111'], 'value': '+'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '108', 'type': 'slice', 'children': ['109', '110']},{'id': '109', 'type': 'colon', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '113', 'type': 'slice', 'children': ['114', '117']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'colon', 'children': []},{'id': '118', 'type': 'elif_clause', 'children': ['119', '122']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'is'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'nsl_type'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'slice'},{'id': '122', 'type': 'block', 'children': ['123', '159', '167', '181']},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '129']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '142']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135', '139'], 'value': '<='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '135', 'type': '()', 'children': ['136']},{'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '%'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'augmented_assignment', 'children': ['145', '146'], 'value': '+='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'newitems'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '148', 'type': 'slice', 'children': ['149', '152', '153']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '*'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '152', 'type': 'colon', 'children': []},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '*'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '+'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '162', 'type': 'subscript', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'redim'},{'id': '170', 'type': 'tuple', 'children': ['171', '176']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'newshape'},{'id': '184', 'type': 'binary_operator', 'children': ['185', '193'], 'value': '+'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '191'], 'value': '+'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '188', 'type': 'slice', 'children': ['189', '190']},{'id': '189', 'type': 'colon', 'children': []},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '191', 'type': 'tuple', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'redim'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '195', 'type': 'slice', 'children': ['196', '199']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '+'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202', '233', '246', '273', '325']},{'id': '202', 'type': 'if_statement', 'children': ['203', '211']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': '<'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'clog2'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '211', 'type': 'block', 'children': ['212', '216']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '215', 'type': 'string', 'children': [], 'value': '"expected dim {} select to have >= {} bits, got {}"'},{'id': '216', 'type': 'raise_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'fstr'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226', '230']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'clog2'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '236', 'type': 'list_comprehension', 'children': ['237', '240']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'for_in_clause', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '246', 'type': 'for_statement', 'children': ['247', '248', '252']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '252', 'type': 'block', 'children': ['253']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'augmented_assignment', 'children': ['255', '260'], 'value': '+='},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '257', 'type': 'binary_operator', 'children': ['258', '259'], 'value': '%'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '262', 'type': 'slice', 'children': ['263', '266', '267']},{'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '*'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '266', 'type': 'colon', 'children': []},{'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '*'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '269', 'type': '()', 'children': ['270']},{'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '272', 'type': 'integer', 'children': [], 'value': '1'},{'id': '273', 'type': 'for_statement', 'children': ['274', '275', '280']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'muxins'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'list_splat', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '280', 'type': 'block', 'children': ['281', '292', '312']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'boolfunc'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'iter_terms'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'nsl'},{'id': '291', 'type': 'identifier', 'children': [], 'value': '_items'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '295', 'type': 'list_comprehension', 'children': ['296', '309']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '298', 'type': 'argument_list', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'and_'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '305'], 'value': '+'},{'id': '303', 'type': 'tuple', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'muxin'},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '309', 'type': 'for_in_clause', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'muxin'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'muxins'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'newitems'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '320', 'type': 'argument_list', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'newshape'},{'id': '328', 'type': 'binary_operator', 'children': ['329', '334'], 'value': '+'},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '331', 'type': 'slice', 'children': ['332', '333']},{'id': '332', 'type': 'colon', 'children': []},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '336', 'type': 'slice', 'children': ['337', '340']},{'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '+'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'dim'},{'id': '339', 'type': 'integer', 'children': [], 'value': '1'},{'id': '340', 'type': 'colon', 'children': []},{'id': '341', 'type': 'return_statement', 'children': ['342']},{'id': '342', 'type': 'expression_list', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'newitems'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'newshape'} | def _filtdim(items, shape, dim, nsl):
normshape = tuple(stop - start for start, stop in shape)
nsl_type = type(nsl)
newitems = list()
num = reduce(operator.mul, normshape[:dim+1])
size = len(items) // num
n = normshape[dim]
if nsl_type is int:
for i in range(num):
if i % n == nsl:
newitems += items[size*i:size*(i+1)]
newshape = shape[:dim] + shape[dim+1:]
elif nsl_type is slice:
for i in range(num):
if nsl.start <= (i % n) < nsl.stop:
newitems += items[size*i:size*(i+1)]
offset = shape[dim][0]
redim = (offset + nsl.start, offset + nsl.stop)
newshape = shape[:dim] + (redim, ) + shape[dim+1:]
else:
if nsl.size < clog2(n):
fstr = "expected dim {} select to have >= {} bits, got {}"
raise ValueError(fstr.format(dim, clog2(n), nsl.size))
groups = [list() for _ in range(n)]
for i in range(num):
groups[i % n] += items[size*i:size*(i+1)]
for muxins in zip(*groups):
it = boolfunc.iter_terms(nsl._items)
xs = [reduce(operator.and_, (muxin, ) + next(it))
for muxin in muxins]
newitems.append(reduce(operator.or_, xs))
newshape = shape[:dim] + shape[dim+1:]
return newitems, newshape |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Docstring'},{'id': '10', 'type': 'block', 'children': ['11', '17', '23', '32', '41', '78', '88', '98', '148', '160', '166', '170', '205', '224', '228', '272', '278', '478']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Docstring'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '20']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cleandoc'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_titles_re'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '41', 'type': 'if_statement', 'children': ['42', '43', '68']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '43', 'type': 'block', 'children': ['44', '56']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'desc_chunk'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '49', 'type': 'slice', 'children': ['50', '51']},{'id': '50', 'type': 'colon', 'children': []},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'meta_chunk'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '61', 'type': 'slice', 'children': ['62', '67']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70', '74']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'desc_chunk'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'meta_chunk'},{'id': '77', 'type': 'string', 'children': [], 'value': '""'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'desc_chunk'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'short_description'},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '97'], 'value': 'or'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '105']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '104'], 'value': '>'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'block', 'children': ['106', '114', '125', '136']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'long_desc_chunk'},{'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'or'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'string', 'children': [], 'value': '""'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'blank_after_short_description'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'long_desc_chunk'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'blank_after_long_description'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'long_desc_chunk'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': '"\\n\\n"'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'long_description'},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '147'], 'value': 'or'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'long_desc_chunk'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_titles_re'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'meta_chunk'},{'id': '160', 'type': 'if_statement', 'children': ['161', '163']},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '169', 'type': 'list', 'children': [], 'value': '[]'},{'id': '170', 'type': 'for_statement', 'children': ['171', '172', '181']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'binary_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': 'matches'},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'tuple', 'children': ['189', '196']},{'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': 'matches'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'call', 'children': ['197', '204']},{'id': '197', 'type': 'attribute', 'children': ['198', '203']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '+'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'tuple', 'children': ['212', '220']},{'id': '212', 'type': 'call', 'children': ['213', '219']},{'id': '213', 'type': 'attribute', 'children': ['214', '218']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '216', 'type': 'unary_operator', 'children': ['217'], 'value': '-'},{'id': '217', 'type': 'integer', 'children': [], 'value': '1'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'meta_chunk'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '227', 'type': 'dictionary', 'children': []},{'id': '228', 'type': 'for_statement', 'children': ['229', '234', '238']},{'id': '229', 'type': 'pattern_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '231', 'type': 'tuple_pattern', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '238', 'type': 'block', 'children': ['239', '250', '256']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '242', 'type': 'call', 'children': ['243', '248']},{'id': '243', 'type': 'attribute', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'integer', 'children': [], 'value': '1'},{'id': '250', 'type': 'if_statement', 'children': ['251', '254']},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': 'not'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_valid'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'continue_statement', 'children': []},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '261']},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '261', 'type': 'call', 'children': ['262', '270']},{'id': '262', 'type': 'attribute', 'children': ['263', '269']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'meta_chunk'},{'id': '265', 'type': 'slice', 'children': ['266', '267', '268']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '267', 'type': 'colon', 'children': []},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '272', 'type': 'if_statement', 'children': ['273', '275']},{'id': '273', 'type': 'not_operator', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '278', 'type': 'for_statement', 'children': ['279', '282', '287']},{'id': '279', 'type': 'pattern_list', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '286', 'type': 'argument_list', 'children': []},{'id': '287', 'type': 'block', 'children': ['288', '298', '307', '315', '347', '355', '373', '382', '386', '421', '440']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'indent_match'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '295', 'type': 'argument_list', 'children': ['296', '297']},{'id': '296', 'type': 'string', 'children': [], 'value': 'r"^\\s+"'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '298', 'type': 'if_statement', 'children': ['299', '301']},{'id': '299', 'type': 'not_operator', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'indent_match'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'raise_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'ParseError'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'string', 'children': [], 'value': 'f\'Can\\\'t infer indent from "{chunk}"\''},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'indent_match'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '314', 'type': 'argument_list', 'children': []},{'id': '315', 'type': 'if_statement', 'children': ['316', '323']},{'id': '316', 'type': 'comparison_operator', 'children': ['317', '320'], 'value': 'in'},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': '_sections'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '320', 'type': 'tuple', 'children': ['321', '322']},{'id': '321', 'type': 'string', 'children': [], 'value': '"returns"'},{'id': '322', 'type': 'string', 'children': [], 'value': '"yields"'},{'id': '323', 'type': 'block', 'children': ['324', '333', '346']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'cleandoc'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '340']},{'id': '335', 'type': 'attribute', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': '_build_meta'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '346', 'type': 'continue_statement', 'children': []},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'assignment', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': '_re'},{'id': '350', 'type': 'binary_operator', 'children': ['351', '354'], 'value': '+'},{'id': '351', 'type': 'binary_operator', 'children': ['352', '353'], 'value': '+'},{'id': '352', 'type': 'string', 'children': [], 'value': '"^"'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '354', 'type': 'string', 'children': [], 'value': 'r"(?=\\S)"'},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'assignment', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '358', 'type': 'call', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '360', 'type': 'argument_list', 'children': ['361']},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '365', 'type': 'argument_list', 'children': ['366', '367', '368']},{'id': '366', 'type': 'identifier', 'children': [], 'value': '_re'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '368', 'type': 'keyword_argument', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '373', 'type': 'if_statement', 'children': ['374', '376']},{'id': '374', 'type': 'not_operator', 'children': ['375']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'raise_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'ParseError'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'string', 'children': [], 'value': 'f\'No specification for "{title}": "{chunk}"\''},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'assignment', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'c_splits'},{'id': '385', 'type': 'list', 'children': [], 'value': '[]'},{'id': '386', 'type': 'for_statement', 'children': ['387', '388', '397']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '388', 'type': 'call', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '390', 'type': 'argument_list', 'children': ['391']},{'id': '391', 'type': 'binary_operator', 'children': ['392', '396'], 'value': '-'},{'id': '392', 'type': 'call', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '394', 'type': 'argument_list', 'children': ['395']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '396', 'type': 'integer', 'children': [], 'value': '1'},{'id': '397', 'type': 'block', 'children': ['398']},{'id': '398', 'type': 'expression_statement', 'children': ['399']},{'id': '399', 'type': 'call', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'c_splits'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '403', 'type': 'argument_list', 'children': ['404']},{'id': '404', 'type': 'tuple', 'children': ['405', '412']},{'id': '405', 'type': 'call', 'children': ['406', '411']},{'id': '406', 'type': 'attribute', 'children': ['407', '410']},{'id': '407', 'type': 'subscript', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '411', 'type': 'argument_list', 'children': []},{'id': '412', 'type': 'call', 'children': ['413', '420']},{'id': '413', 'type': 'attribute', 'children': ['414', '419']},{'id': '414', 'type': 'subscript', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '416', 'type': 'binary_operator', 'children': ['417', '418'], 'value': '+'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '418', 'type': 'integer', 'children': [], 'value': '1'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '420', 'type': 'argument_list', 'children': []},{'id': '421', 'type': 'expression_statement', 'children': ['422']},{'id': '422', 'type': 'call', 'children': ['423', '426']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'c_splits'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '426', 'type': 'argument_list', 'children': ['427']},{'id': '427', 'type': 'tuple', 'children': ['428', '436']},{'id': '428', 'type': 'call', 'children': ['429', '435']},{'id': '429', 'type': 'attribute', 'children': ['430', '434']},{'id': '430', 'type': 'subscript', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'c_matches'},{'id': '432', 'type': 'unary_operator', 'children': ['433'], 'value': '-'},{'id': '433', 'type': 'integer', 'children': [], 'value': '1'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '435', 'type': 'argument_list', 'children': []},{'id': '436', 'type': 'call', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '438', 'type': 'argument_list', 'children': ['439']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '440', 'type': 'for_statement', 'children': ['441', '446', '450']},{'id': '441', 'type': 'pattern_list', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '443', 'type': 'tuple_pattern', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '446', 'type': 'call', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '448', 'type': 'argument_list', 'children': ['449']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'c_splits'},{'id': '450', 'type': 'block', 'children': ['451', '465']},{'id': '451', 'type': 'expression_statement', 'children': ['452']},{'id': '452', 'type': 'assignment', 'children': ['453', '454']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '454', 'type': 'call', 'children': ['455', '463']},{'id': '455', 'type': 'attribute', 'children': ['456', '462']},{'id': '456', 'type': 'subscript', 'children': ['457', '458']},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '458', 'type': 'slice', 'children': ['459', '460', '461']},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '460', 'type': 'colon', 'children': []},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '463', 'type': 'argument_list', 'children': ['464']},{'id': '464', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '465', 'type': 'expression_statement', 'children': ['466']},{'id': '466', 'type': 'call', 'children': ['467', '472']},{'id': '467', 'type': 'attribute', 'children': ['468', '471']},{'id': '468', 'type': 'attribute', 'children': ['469', '470']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '470', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '472', 'type': 'argument_list', 'children': ['473']},{'id': '473', 'type': 'call', 'children': ['474', '475']},{'id': '474', 'type': 'identifier', 'children': [], 'value': '_build_meta'},{'id': '475', 'type': 'argument_list', 'children': ['476', '477']},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '477', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '478', 'type': 'return_statement', 'children': ['479']},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'ret'} | def parse(text: str) -> Docstring:
ret = Docstring()
if not text:
return ret
text = inspect.cleandoc(text)
match = _titles_re.search(text)
if match:
desc_chunk = text[: match.start()]
meta_chunk = text[match.start() :]
else:
desc_chunk = text
meta_chunk = ""
parts = desc_chunk.split("\n", 1)
ret.short_description = parts[0] or None
if len(parts) > 1:
long_desc_chunk = parts[1] or ""
ret.blank_after_short_description = long_desc_chunk.startswith("\n")
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
ret.long_description = long_desc_chunk.strip() or None
matches = list(_titles_re.finditer(meta_chunk))
if not matches:
return ret
splits = []
for j in range(len(matches) - 1):
splits.append((matches[j].end(), matches[j + 1].start()))
splits.append((matches[-1].end(), len(meta_chunk)))
chunks = {}
for j, (start, end) in enumerate(splits):
title = matches[j].group(1)
if title not in _valid:
continue
chunks[title] = meta_chunk[start:end].strip("\n")
if not chunks:
return ret
for title, chunk in chunks.items():
indent_match = re.search(r"^\s+", chunk)
if not indent_match:
raise ParseError(f'Can\'t infer indent from "{chunk}"')
indent = indent_match.group()
if _sections[title] in ("returns", "yields"):
part = inspect.cleandoc(chunk)
ret.meta.append(_build_meta(part, title))
continue
_re = "^" + indent + r"(?=\S)"
c_matches = list(re.finditer(_re, chunk, flags=re.M))
if not c_matches:
raise ParseError(f'No specification for "{title}": "{chunk}"')
c_splits = []
for j in range(len(c_matches) - 1):
c_splits.append((c_matches[j].end(), c_matches[j + 1].start()))
c_splits.append((c_matches[-1].end(), len(chunk)))
for j, (start, end) in enumerate(c_splits):
part = chunk[start:end].strip("\n")
ret.meta.append(_build_meta(part, title))
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'copied'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17', '38', '42']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'if_statement', 'children': ['18', '20', '31']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '20', 'type': 'block', 'children': ['21', '28']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"Workspace supports one tool for all projects within."'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'unary_operator', 'children': ['30'], 'value': '-'},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'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': 'tools'},{'id': '36', 'type': 'list', 'children': ['37'], 'value': '[tool]'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'export_tool'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'tools'},{'id': '45', 'type': 'block', 'children': ['46', '57', '68', '72', '126', '152', '177', '269', '285', '293']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tool_export'},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ToolsSupported'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_tool'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'export_tool'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'tool_export'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '67']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '65', 'type': 'unary_operator', 'children': ['66'], 'value': '-'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'continue_statement', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'project_export_dir_overwrite'},{'id': '71', 'type': 'False', 'children': []},{'id': '72', 'type': 'if_statement', 'children': ['73', '84', '93']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '79'], 'value': '!='},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'export_location_format'},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_EXPORT_LOCATION_FORMAT'},{'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': 'location_format'},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'export_location_format'},{'id': '93', 'type': 'else_clause', 'children': ['94']},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '101', '116']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'in'},{'id': '97', 'type': 'string', 'children': [], 'value': "'export_dir'"},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'workspace_settings'},{'id': '101', 'type': 'block', 'children': ['102', '112']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'location_format'},{'id': '105', 'type': 'subscript', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'workspace_settings'},{'id': '110', 'type': 'string', 'children': [], 'value': "'export_dir'"},{'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': 'project_export_dir_overwrite'},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'else_clause', 'children': ['117']},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'location_format'},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'export_location_format'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'PartialFormatter'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'location_format'},{'id': '137', 'type': 'dictionary_splat', 'children': ['138']},{'id': '138', 'type': 'dictionary', 'children': ['139', '144', '147']},{'id': '139', 'type': 'pair', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'project_name'"},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'pair', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': "'tool'"},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'workspace_name'"},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'workspace_dic'},{'id': '155', 'type': 'dictionary', 'children': ['156', '159']},{'id': '156', 'type': 'pair', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '158', 'type': 'list', 'children': [], 'value': '[]'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "'settings'"},{'id': '161', 'type': 'dictionary', 'children': ['162', '167']},{'id': '162', 'type': 'pair', 'children': ['163', '164']},{'id': '163', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '167', 'type': 'pair', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '169', 'type': 'call', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '177', 'type': 'for_statement', 'children': ['178', '179', '182']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'projects'},{'id': '182', 'type': 'block', 'children': ['183', '193', '206', '214', '223', '233', '251', '260']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'generated_files'},{'id': '186', 'type': 'dictionary', 'children': ['187', '190']},{'id': '187', 'type': 'pair', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '189', 'type': 'list', 'children': [], 'value': '[]'},{'id': '190', 'type': 'pair', 'children': ['191', '192']},{'id': '191', 'type': 'string', 'children': [], 'value': "'workspaces'"},{'id': '192', 'type': 'list', 'children': [], 'value': '[]'},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'project_export_dir_overwrite'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '205']},{'id': '198', 'type': 'subscript', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '203', 'type': 'string', 'children': [], 'value': "'common'"},{'id': '204', 'type': 'string', 'children': [], 'value': "'export_dir'"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'location'},{'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': 'project'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_fill_export_dict'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'export_tool'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'copied'},{'id': '214', 'type': 'if_statement', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '216', 'type': 'block', 'children': ['217']},{'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': 'project'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_copy_sources_to_generated_destination'},{'id': '222', 'type': 'argument_list', 'children': []},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '232']},{'id': '225', 'type': 'subscript', 'children': ['226', '231']},{'id': '226', 'type': 'subscript', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '230', 'type': 'string', 'children': [], 'value': "'export'"},{'id': '231', 'type': 'string', 'children': [], 'value': "'singular'"},{'id': '232', 'type': 'False', 'children': []},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '236', 'type': 'call', 'children': ['237', '250']},{'id': '237', 'type': 'attribute', 'children': ['238', '249']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'tool_export'},{'id': '240', 'type': 'argument_list', 'children': ['241', '246']},{'id': '241', 'type': 'subscript', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '245', 'type': 'string', 'children': [], 'value': "'export'"},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'export_project'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '258']},{'id': '253', 'type': 'attribute', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'workspace_dic'},{'id': '256', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '267']},{'id': '262', 'type': 'attribute', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'generated_files'},{'id': '265', 'type': 'string', 'children': [], 'value': "'projects'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'generated_files'},{'id': '273', 'type': 'string', 'children': [], 'value': "'workspaces'"},{'id': '274', 'type': 'call', 'children': ['275', '284']},{'id': '275', 'type': 'attribute', 'children': ['276', '283']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'tool_export'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'workspace_dic'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'export_workspace'},{'id': '284', 'type': 'argument_list', 'children': []},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '292']},{'id': '287', 'type': 'subscript', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'generated_files'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'export_tool'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'generated_files'},{'id': '293', 'type': 'return_statement', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'result'} | def generate(self, tool, copied=False, copy=False):
tools = []
if not tool:
logger.info("Workspace supports one tool for all projects within.")
return -1
else:
tools = [tool]
result = 0
for export_tool in tools:
tool_export = ToolsSupported().get_tool(export_tool)
if tool_export is None:
result = -1
continue
project_export_dir_overwrite = False
if self.settings.export_location_format != self.settings.DEFAULT_EXPORT_LOCATION_FORMAT:
location_format = self.settings.export_location_format
else:
if 'export_dir' in self.workspace_settings:
location_format = self.workspace_settings['export_dir'][0]
project_export_dir_overwrite = True
else:
location_format = self.settings.export_location_format
location = PartialFormatter().format(location_format, **{
'project_name': self.name,
'tool': tool,
'workspace_name': self.name
})
workspace_dic = {
'projects': [],
'settings': {
'name': self.name,
'path': os.path.normpath(location),
},
}
for project in self.projects:
generated_files = {
'projects' : [],
'workspaces': [],
}
if project_export_dir_overwrite:
project.project['common']['export_dir'] = location
project._fill_export_dict(export_tool, copied)
if copy:
project._copy_sources_to_generated_destination()
project.project['export']['singular'] = False
files = tool_export(project.project['export'], self.settings).export_project()
workspace_dic['projects'].append(files)
generated_files['projects'].append(files)
generated_files['workspaces'] = tool_export(workspace_dic, self.settings).export_workspace()
self.generated_files[export_tool] = generated_files
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_send_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '16', '31', '40', '46', '70', '79', '109', '116', '153', '159', '190', '244', '252', '260', '266', '302']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '10', 'type': 'dictionary', 'children': ['11']},{'id': '11', 'type': 'pair', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': '"X-Experience-API-Version"'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '16', 'type': 'if_statement', 'children': ['17', '22']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': 'is'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'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': 'headers'},{'id': '27', 'type': 'string', 'children': [], 'value': '"Authorization"'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'auth'},{'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': 'headers'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '49', 'type': 'dictionary_comprehension', 'children': ['50', '63']},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'call', 'children': ['53', '61']},{'id': '53', 'type': 'attribute', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '63', 'type': 'for_in_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '79', 'type': 'if_statement', 'children': ['80', '88', '95']},{'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': 'request'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': "'http'"},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97', '103']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'augmented_assignment', 'children': ['105', '106'], 'value': '+='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '116', 'type': 'if_statement', 'children': ['117', '122', '137']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '=='},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '121', 'type': 'string', 'children': [], 'value': '"https"'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'web_req'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'httplib'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'HTTPSConnection'},{'id': '130', 'type': 'argument_list', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '137', 'type': 'else_clause', 'children': ['138']},{'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': 'web_req'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'httplib'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'HTTPConnection'},{'id': '146', 'type': 'argument_list', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '159', 'type': 'if_statement', 'children': ['160', '167']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '164'], 'value': 'or'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '167', 'type': 'block', 'children': ['168', '172', '183']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '171', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '172', 'type': 'if_statement', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'augmented_assignment', 'children': ['179', '180'], 'value': '+='},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '183', 'type': 'if_statement', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'augmented_assignment', 'children': ['188', '189'], 'value': '+='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '190', 'type': 'if_statement', 'children': ['191', '202', '225']},{'id': '191', 'type': 'boolean_operator', 'children': ['192', '197'], 'value': 'and'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '196', 'type': 'string', 'children': [], 'value': '"content"'},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': 'is'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'block', 'children': ['203']},{'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': 'web_req'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '208', 'type': 'argument_list', 'children': ['209', '214', '217', '222']},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '225', 'type': 'else_clause', 'children': ['226']},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'web_req'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '232', 'type': 'argument_list', 'children': ['233', '238', '241']},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'web_req'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'getresponse'},{'id': '251', 'type': 'argument_list', 'children': []},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '259', 'type': 'argument_list', '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': 'web_req'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '265', 'type': 'argument_list', 'children': []},{'id': '266', 'type': 'if_statement', 'children': ['267', '291', '296']},{'id': '267', 'type': '()', 'children': ['268']},{'id': '268', 'type': 'boolean_operator', 'children': ['269', '275'], 'value': 'or'},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '271', '274'], 'value': '<='},{'id': '270', 'type': 'integer', 'children': [], 'value': '200'},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '274', 'type': 'integer', 'children': [], 'value': '300'},{'id': '275', 'type': '()', 'children': ['276']},{'id': '276', 'type': 'boolean_operator', 'children': ['277', '288'], 'value': 'and'},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '283'], 'value': 'and'},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '282'], 'value': '=='},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '282', 'type': 'integer', 'children': [], 'value': '404'},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '285', 'type': 'argument_list', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '287', 'type': 'string', 'children': [], 'value': '"ignore404"'},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'ignore404'},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '295', 'type': 'True', 'children': []},{'id': '296', 'type': 'else_clause', 'children': ['297']},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '301', 'type': 'False', 'children': []},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'LRSResponse'},{'id': '305', 'type': 'argument_list', 'children': ['306', '309', '312', '315']},{'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'data'} | def _send_request(self, request):
headers = {"X-Experience-API-Version": self.version}
if self.auth is not None:
headers["Authorization"] = self.auth
headers.update(request.headers)
params = request.query_params
params = {k: unicode(params[k]).encode('utf-8') for k in params.keys()}
params = urllib.urlencode(params)
if request.resource.startswith('http'):
url = request.resource
else:
url = self.endpoint
url += request.resource
parsed = urlparse(url)
if parsed.scheme == "https":
web_req = httplib.HTTPSConnection(parsed.hostname, parsed.port)
else:
web_req = httplib.HTTPConnection(parsed.hostname, parsed.port)
path = parsed.path
if parsed.query or parsed.path:
path += "?"
if parsed.query:
path += parsed.query
if params:
path += params
if hasattr(request, "content") and request.content is not None:
web_req.request(
method=request.method,
url=path,
body=request.content,
headers=headers,
)
else:
web_req.request(
method=request.method,
url=path,
headers=headers,
)
response = web_req.getresponse()
data = response.read()
web_req.close()
if (200 <= response.status < 300
or (response.status == 404
and hasattr(request, "ignore404")
and request.ignore404)):
success = True
else:
success = False
return LRSResponse(
success=success,
request=request,
response=response,
data=data,
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_statements'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'block', 'children': ['7', '11', '24', '85', '97', '103', '112', '130']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'params'},{'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': 'param_keys'},{'id': '14', 'type': 'list', 'children': ['15', '16', '17', '18', '19', '20', '21', '22', '23'], 'value': '[\n "registration",\n "since",\n "until",\n "limit",\n "ascending",\n "related_activities",\n "related_agents",\n "format",\n "attachments",\n ]'},{'id': '15', 'type': 'string', 'children': [], 'value': '"registration"'},{'id': '16', 'type': 'string', 'children': [], 'value': '"since"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"until"'},{'id': '18', 'type': 'string', 'children': [], 'value': '"limit"'},{'id': '19', 'type': 'string', 'children': [], 'value': '"ascending"'},{'id': '20', 'type': 'string', 'children': [], 'value': '"related_activities"'},{'id': '21', 'type': 'string', 'children': [], 'value': '"related_agents"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"format"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"attachments"'},{'id': '24', 'type': 'for_statement', 'children': ['25', '28', '33']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '57', '74']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'string', 'children': [], 'value': '"agent"'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '57', 'type': 'elif_clause', 'children': ['58', '65']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '62'], 'value': 'or'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '=='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '61', 'type': 'string', 'children': [], 'value': '"verb"'},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '64', 'type': 'string', 'children': [], 'value': '"activity"'},{'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': 'params'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '74', 'type': 'elif_clause', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'param_keys'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'HTTPRequest'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94']},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '93', 'type': 'string', 'children': [], 'value': '"GET"'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '96', 'type': 'string', 'children': [], 'value': '"statements"'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'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': '_send_request'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'StatementsResult'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'from_json'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'lrs_response'} | def query_statements(self, query):
params = {}
param_keys = [
"registration",
"since",
"until",
"limit",
"ascending",
"related_activities",
"related_agents",
"format",
"attachments",
]
for k, v in query.iteritems():
if v is not None:
if k == "agent":
params[k] = v.to_json(self.version)
elif k == "verb" or k == "activity":
params[k] = v.id
elif k in param_keys:
params[k] = v
request = HTTPRequest(
method="GET",
resource="statements"
)
request.query_params = params
lrs_response = self._send_request(request)
if lrs_response.success:
lrs_response.content = StatementsResult.from_json(lrs_response.data)
return lrs_response |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'retrieve_state'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'state_id'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '27', '42', '57', '81', '94', '103', '212']},{'id': '12', 'type': 'if_statement', 'children': ['13', '19']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Activity'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Activity'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '27', 'type': 'if_statement', 'children': ['28', '34']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Agent'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'HTTPRequest'},{'id': '47', 'type': 'argument_list', 'children': ['48', '51', '54']},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '50', 'type': 'string', 'children': [], 'value': '"GET"'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '53', 'type': 'string', 'children': [], 'value': '"activities/state"'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ignore404'},{'id': '56', 'type': 'True', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '62', 'type': 'dictionary', 'children': ['63', '68', '78']},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': '"activityId"'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': '"agent"'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"stateId"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'state_id'},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '92', 'type': 'string', 'children': [], 'value': '"registration"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_send_request'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '107', 'type': 'block', 'children': ['108', '128', '139', '149', '168', '187', '206']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'StateDocument'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117', '122', '125']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'state_id'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'activity'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'agent'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'registration'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'headers'},{'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': 'lrs_response'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'getheaders'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'if_statement', 'children': ['150', '159']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '154'], 'value': 'and'},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'in'},{'id': '152', 'type': 'string', 'children': [], 'value': '"lastModified"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '158'], 'value': 'is'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '157', 'type': 'string', 'children': [], 'value': '"lastModified"'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '167', 'type': 'string', 'children': [], 'value': '"lastModified"'},{'id': '168', 'type': 'if_statement', 'children': ['169', '178']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '173'], 'value': 'and'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'in'},{'id': '171', 'type': 'string', 'children': [], 'value': '"contentType"'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '177'], 'value': 'is'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '176', 'type': 'string', 'children': [], 'value': '"contentType"'},{'id': '177', 'type': 'None', 'children': []},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '186', 'type': 'string', 'children': [], 'value': '"contentType"'},{'id': '187', 'type': 'if_statement', 'children': ['188', '197']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'string', 'children': [], 'value': '"etag"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': 'is'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '195', 'type': 'string', 'children': [], 'value': '"etag"'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'etag'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '205', 'type': 'string', 'children': [], 'value': '"etag"'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'lrs_response'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'lrs_response'} | def retrieve_state(self, activity, agent, state_id, registration=None):
if not isinstance(activity, Activity):
activity = Activity(activity)
if not isinstance(agent, Agent):
agent = Agent(agent)
request = HTTPRequest(
method="GET",
resource="activities/state",
ignore404=True
)
request.query_params = {
"activityId": activity.id,
"agent": agent.to_json(self.version),
"stateId": state_id
}
if registration is not None:
request.query_params["registration"] = registration
lrs_response = self._send_request(request)
if lrs_response.success:
doc = StateDocument(
id=state_id,
content=lrs_response.data,
activity=activity,
agent=agent
)
if registration is not None:
doc.registration = registration
headers = lrs_response.response.getheaders()
if "lastModified" in headers and headers["lastModified"] is not None:
doc.timestamp = headers["lastModified"]
if "contentType" in headers and headers["contentType"] is not None:
doc.content_type = headers["contentType"]
if "etag" in headers and headers["etag"] is not None:
doc.etag = headers["etag"]
lrs_response.content = doc
return lrs_response |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_version'},{'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': 'version'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Version'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'latest'},{'id': '10', 'type': 'block', 'children': ['11', '235']},{'id': '11', 'type': 'if_statement', 'children': ['12', '18', '197']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'block', 'children': ['19', '23', '188']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '46']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '27', 'type': 'conditional_expression', 'children': ['28', '33', '38'], 'value': 'if'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '32', 'type': 'argument_list', 'children': []},{'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': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '38', 'type': 'call', 'children': ['39', '45']},{'id': '39', 'type': 'attribute', 'children': ['40', '44']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '59']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': '_props_corrected'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '59', 'type': 'if_statement', 'children': ['60', '65', '77', '126', '144', '162', '180']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'SerializableBase'},{'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': 'result'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'as_version'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '77', 'type': 'elif_clause', 'children': ['78', '83']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '83', 'type': 'block', 'children': ['84', '90']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '89', 'type': 'list', 'children': [], 'value': '[]'},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'if_statement', 'children': ['95', '100', '115']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'SerializableBase'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'as_version'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '134']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'UUID'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '144', 'type': 'elif_clause', 'children': ['145', '152']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'jsonify_timedelta'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '162', 'type': 'elif_clause', 'children': ['163', '170']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'jsonify_datetime'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_filter_none'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '197', 'type': 'else_clause', 'children': ['198']},{'id': '198', 'type': 'block', 'children': ['199', '203']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '202', 'type': 'list', 'children': [], 'value': '[]'},{'id': '203', 'type': 'for_statement', 'children': ['204', '205', '206']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'if_statement', 'children': ['208', '213', '226']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'SerializableBase'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'as_version'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '235', 'type': 'return_statement', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'result'} | def as_version(self, version=Version.latest):
if not isinstance(self, list):
result = {}
for k, v in self.iteritems() if isinstance(self, dict) else vars(self).iteritems():
k = self._props_corrected.get(k, k)
if isinstance(v, SerializableBase):
result[k] = v.as_version(version)
elif isinstance(v, list):
result[k] = []
for val in v:
if isinstance(val, SerializableBase):
result[k].append(val.as_version(version))
else:
result[k].append(val)
elif isinstance(v, uuid.UUID):
result[k] = unicode(v)
elif isinstance(v, datetime.timedelta):
result[k] = jsonify_timedelta(v)
elif isinstance(v, datetime.datetime):
result[k] = jsonify_datetime(v)
else:
result[k] = v
result = self._filter_none(result)
else:
result = []
for v in self:
if isinstance(v, SerializableBase):
result.append(v.as_version(version))
else:
result.append(v)
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'xrun'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_log_container_as_started'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logfile'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'kill_callback'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '42', '70', '98', '108', '116', '124', '130']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': '" "'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'binary_operator', 'children': ['32', '34'], 'value': '+'},{'id': '32', 'type': 'list', 'children': ['33'], 'value': '[command]'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '42', 'type': 'function_definition', 'children': ['43', '44', '46']},{'id': '43', 'type': 'function_name', 'children': [], 'value': '_print_info'},{'id': '44', 'type': 'parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '46', 'type': 'block', 'children': ['47', '53']},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': []},{'id': '53', 'type': 'if_statement', 'children': ['54', '55', '63']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'log'},{'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': 'log'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '70', 'type': 'function_definition', 'children': ['71', '72', '74']},{'id': '71', 'type': 'function_name', 'children': [], 'value': '_print_warn'},{'id': '72', 'type': 'parameters', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '74', 'type': 'block', 'children': ['75', '81']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '83', '91']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'log'},{'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': 'log'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': '_print_info'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': 'u"Running: {0:s}"'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'try_statement', 'children': ['131', '359']},{'id': '131', 'type': 'block', 'children': ['132', '164', '338']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'foutname'},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"/tmp"'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"stimela_output_{0:s}_{1:f}"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '147', 'type': 'argument_list', 'children': ['148', '163']},{'id': '148', 'type': 'call', 'children': ['149', '162']},{'id': '149', 'type': 'attribute', 'children': ['150', '161']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'md5'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '164', 'type': 'with_statement', 'children': ['165', '175']},{'id': '165', 'type': 'with_clause', 'children': ['166']},{'id': '166', 'type': 'with_item', 'children': ['167']},{'id': '167', 'type': 'as_pattern', 'children': ['168', '173']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'foutname'},{'id': '172', 'type': 'string', 'children': [], 'value': '"w+"'},{'id': '173', 'type': 'as_pattern_target', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '175', 'type': 'block', 'children': ['176', '196', '274', '292', '331']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '190', '193']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '195', 'type': 'True', 'children': []},{'id': '196', 'type': 'function_definition', 'children': ['197', '198', '200']},{'id': '197', 'type': 'function_name', 'children': [], 'value': 'clock_killer'},{'id': '198', 'type': 'parameters', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'while_statement', 'children': ['202', '214']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '210'], 'value': 'and'},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '209'], 'value': 'is'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '208', 'type': 'argument_list', 'children': []},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': '()', 'children': ['211']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': '>='},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'block', 'children': ['215', '223', '267']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'currenttime'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '222', 'type': 'argument_list', 'children': []},{'id': '223', 'type': 'if_statement', 'children': ['224', '230', '246']},{'id': '224', 'type': '()', 'children': ['225']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '229'], 'value': '<'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '-'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'currenttime'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'boolean_operator', 'children': ['233', '234'], 'value': 'and'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_print_warn'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'string', 'children': [], 'value': 'u"Clock Reaper: has been running for {0:f}, must finish in {1:f}"'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '241', 'type': 'argument_list', 'children': ['242', '245']},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '-'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'currenttime'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '246', 'type': 'else_clause', 'children': ['247']},{'id': '247', 'type': 'block', 'children': ['248', '258']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': '_print_warn'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'string', 'children': [], 'value': 'u"Clock Reaper: Timeout reached for \'{0:s}\'... sending the KILL signal"'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'boolean_operator', 'children': ['260', '264'], 'value': 'and'},{'id': '260', 'type': '()', 'children': ['261']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': 'is'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'kill_callback'},{'id': '263', 'type': 'None', 'children': []},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'kill_callback'},{'id': '266', 'type': 'argument_list', 'children': []},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'INTERRUPT_TIME'},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '291']},{'id': '276', 'type': 'attribute', 'children': ['277', '290']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'Thread'},{'id': '279', 'type': 'argument_list', 'children': ['280', '283']},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'clock_killer'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'list', 'children': ['289'], 'value': '[p]'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '291', 'type': 'argument_list', 'children': []},{'id': '292', 'type': 'while_statement', 'children': ['293', '301']},{'id': '293', 'type': '()', 'children': ['294']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '300'], 'value': 'is'},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'None', 'children': []},{'id': '301', 'type': 'block', 'children': ['302', '310', '324']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'currenttime'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '309', 'type': 'argument_list', 'children': []},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'boolean_operator', 'children': ['312', '313'], 'value': 'and'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': '_print_info'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'string', 'children': [], 'value': 'u"God mode on: has been running for {0:f}"'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '-'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'currenttime'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'INTERRUPT_TIME'},{'id': '331', 'type': 'assert_statement', 'children': ['332', '337']},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '334', 'type': 'argument_list', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '336', 'type': 'string', 'children': [], 'value': '"returncode"'},{'id': '337', 'type': 'string', 'children': [], 'value': '"No returncode after termination!"'},{'id': '338', 'type': 'with_statement', 'children': ['339', '349']},{'id': '339', 'type': 'with_clause', 'children': ['340']},{'id': '340', 'type': 'with_item', 'children': ['341']},{'id': '341', 'type': 'as_pattern', 'children': ['342', '347']},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '344', 'type': 'argument_list', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'foutname'},{'id': '346', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '347', 'type': 'as_pattern_target', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': '_print_info'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '358', 'type': 'argument_list', 'children': []},{'id': '359', 'type': 'finally_clause', 'children': ['360']},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'if_statement', 'children': ['362', '370']},{'id': '362', 'type': 'boolean_operator', 'children': ['363', '367'], 'value': 'and'},{'id': '363', 'type': '()', 'children': ['364']},{'id': '364', 'type': 'comparison_operator', 'children': ['365', '366'], 'value': 'is'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '366', 'type': 'None', 'children': []},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '370', 'type': 'block', 'children': ['371']},{'id': '371', 'type': 'raise_statement', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'StimelaCabRuntimeError'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'binary_operator', 'children': ['376', '377'], 'value': '%'},{'id': '376', 'type': 'string', 'children': [], 'value': "'%s: returns errr code %d'"},{'id': '377', 'type': 'tuple', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'returncode'} | def xrun(command, options, log=None, _log_container_as_started=False, logfile=None, timeout=-1, kill_callback=None):
cmd = " ".join([command] + list(map(str, options)) )
def _print_info(msg):
if msg is None: return
if log:
log.info(msg)
else:
print(msg)
def _print_warn(msg):
if msg is None: return
if log:
log.warn(msg)
else:
print(msg)
_print_info(u"Running: {0:s}".format(cmd))
sys.stdout.flush()
starttime = time.time()
process = p = None
try:
foutname = os.path.join("/tmp", "stimela_output_{0:s}_{1:f}".format(hashlib.md5(cmd.encode('utf-8')).hexdigest(), starttime))
with open(foutname, "w+") as fout:
p = process = subprocess.Popen(cmd,
stderr=fout,
stdout=fout,
shell=True)
def clock_killer(p):
while process.poll() is None and (timeout >= 0):
currenttime = time.time()
if (currenttime - starttime < timeout):
DEBUG and _print_warn(u"Clock Reaper: has been running for {0:f}, must finish in {1:f}".format(currenttime - starttime, timeout))
else:
_print_warn(u"Clock Reaper: Timeout reached for '{0:s}'... sending the KILL signal".format(cmd))
(kill_callback is not None) and kill_callback()
time.sleep(INTERRUPT_TIME)
Thread(target=clock_killer, args=tuple([p])).start()
while (process.poll() is None):
currenttime = time.time()
DEBUG and _print_info(u"God mode on: has been running for {0:f}".format(currenttime - starttime))
time.sleep(INTERRUPT_TIME)
assert hasattr(process, "returncode"), "No returncode after termination!"
with open(foutname, "r") as fout:
_print_info(fout.read())
finally:
if (process is not None) and process.returncode:
raise StimelaCabRuntimeError('%s: returns errr code %d' % (command, process.returncode)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_items'},{'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': 'func'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'return_statement', 'children': ['10']},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '21']},{'id': '11', 'type': 'tuple', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'subscript', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '32', 'type': 'argument_list', 'children': []} | def to_items(self, func=str):
return [
(key, func(self.kwargs[key]))
for key in sorted(self.kwargs.keys())
] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_apply_sub_frames'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'subs'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'for_statement', 'children': ['9', '12', '17']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'subs'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '22', '26', '61', '65', '238']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'expect_map'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '40', '58']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'string', 'children': [], 'value': "'$sub'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'$sub'"},{'id': '40', 'type': 'elif_clause', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'},{'id': '42', 'type': 'string', 'children': [], 'value': "'$sub.'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '44', 'type': 'block', 'children': ['45', '54']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'$sub.'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'expect_map'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'continue_statement', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'raw_subs'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '68', 'type': 'block', 'children': ['69', '79', '85', '201', '205', '214', '229']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_path_to_value'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'continue_statement', 'children': []},{'id': '85', 'type': 'if_statement', 'children': ['86', '91', '166', '194']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'if_statement', 'children': ['93', '94', '150']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'expect_map'},{'id': '94', 'type': 'block', 'children': ['95', '103']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'raw_subs'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'for_statement', 'children': ['104', '107', '112']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '119', '139']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '125', 'type': 'list_comprehension', 'children': ['126', '130', '133']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '133', 'type': 'if_clause', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152', '159']},{'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': 'raw_subs'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '166', 'type': 'elif_clause', 'children': ['167', '172']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '172', 'type': 'block', 'children': ['173', '177']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'augmented_assignment', 'children': ['175', '176'], 'value': '+='},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'raw_subs'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '180', 'type': 'list_comprehension', 'children': ['181', '185', '188']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '185', 'type': 'for_in_clause', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '188', 'type': 'if_clause', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '194', 'type': 'else_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'raise_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'string', 'children': [], 'value': "'Not a supported sub-frame type'"},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_path_to_keys'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '214', 'type': 'for_statement', 'children': ['215', '216', '222']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '218', 'type': 'slice', 'children': ['219', '220']},{'id': '219', 'type': 'colon', 'children': []},{'id': '220', 'type': 'unary_operator', 'children': ['221'], 'value': '-'},{'id': '221', 'type': 'integer', 'children': [], 'value': '1'},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '237']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '235', 'type': 'unary_operator', 'children': ['236'], 'value': '-'},{'id': '236', 'type': 'integer', 'children': [], 'value': '1'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '238', 'type': 'if_statement', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_apply_projection'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'raw_subs'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'projection'} | def _apply_sub_frames(cls, documents, subs):
for path, projection in subs.items():
sub = None
expect_map = False
if '$sub' in projection:
sub = projection.pop('$sub')
elif '$sub.' in projection:
sub = projection.pop('$sub.')
expect_map = True
else:
continue
raw_subs = []
for document in documents:
value = cls._path_to_value(path, document)
if value is None:
continue
if isinstance(value, dict):
if expect_map:
raw_subs += value.values()
for k, v in value.items():
if isinstance(v ,list):
value[k] = [
sub(u) for u in v if isinstance(u, dict)]
else:
value[k] = sub(v)
else:
raw_subs.append(value)
value = sub(value)
elif isinstance(value, list):
raw_subs += value
value = [sub(v) for v in value if isinstance(v, dict)]
else:
raise TypeError('Not a supported sub-frame type')
child_document = document
keys = cls._path_to_keys(path)
for key in keys[:-1]:
child_document = child_document[key]
child_document[keys[-1]] = value
if projection:
sub._apply_projection(raw_subs, projection) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_dereference'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'for_statement', 'children': ['9', '12', '17']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '24', '30', '90', '99', '120', '132']},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'},{'id': '20', 'type': 'string', 'children': [], 'value': "'$ref'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'continue_statement', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '33', 'type': 'block', 'children': ['34', '44', '49']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_path_to_value'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '44', 'type': 'if_statement', 'children': ['45', '47']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'continue_statement', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '55', '63', '81']},{'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': 'value'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'ids'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '63', 'type': 'elif_clause', 'children': ['64', '69']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': "'$ref'"},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'many'},{'id': '106', 'type': 'argument_list', 'children': ['107', '117']},{'id': '107', 'type': 'dictionary', 'children': ['108']},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'_id'"},{'id': '110', 'type': 'dictionary', 'children': ['111']},{'id': '111', 'type': 'pair', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'$in'"},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '123', 'type': 'dictionary_comprehension', 'children': ['124', '129']},{'id': '124', 'type': 'pair', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_id'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '135', 'type': 'block', 'children': ['136', '146', '151', '212', '216', '225', '240']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '_path_to_value'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '146', 'type': 'if_statement', 'children': ['147', '149']},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'continue_statement', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '157', '172', '200']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '161', 'type': 'list_comprehension', 'children': ['162', '165', '168']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '165', 'type': 'for_in_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '168', 'type': 'if_clause', 'children': ['169']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'in'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '172', 'type': 'elif_clause', 'children': ['173', '178']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '182', 'type': 'dictionary_comprehension', 'children': ['183', '191']},{'id': '183', 'type': 'pair', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '191', 'type': 'for_in_clause', 'children': ['192', '195']},{'id': '192', 'type': 'pattern_list', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '211', 'type': 'None', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_path_to_keys'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '233']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '229', 'type': 'slice', 'children': ['230', '231']},{'id': '230', 'type': 'colon', 'children': []},{'id': '231', 'type': 'unary_operator', 'children': ['232'], 'value': '-'},{'id': '232', 'type': 'integer', 'children': [], 'value': '1'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '248']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'child_document'},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '246', 'type': 'unary_operator', 'children': ['247'], 'value': '-'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'value'} | def _dereference(cls, documents, references):
for path, projection in references.items():
if '$ref' not in projection:
continue
ids = set()
for document in documents:
value = cls._path_to_value(path, document)
if not value:
continue
if isinstance(value, list):
ids.update(value)
elif isinstance(value, dict):
ids.update(value.values())
else:
ids.add(value)
ref = projection.pop('$ref')
frames = ref.many(
{'_id': {'$in': list(ids)}},
projection=projection
)
frames = {f._id: f for f in frames}
for document in documents:
value = cls._path_to_value(path, document)
if not value:
continue
if isinstance(value, list):
value = [frames[id] for id in value if id in frames]
elif isinstance(value, dict):
value = {key: frames.get(id) for key, id in value.items()}
else:
value = frames.get(value, None)
child_document = document
keys = cls._path_to_keys(path)
for key in keys[:-1]:
child_document = child_document[key]
child_document[keys[-1]] = value |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'p'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sample_size'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '7', 'type': 'block', 'children': ['8', '14', '21', '28', '32', '36', '125']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'weight_i'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'weights_sum'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'other_weights'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '28', 'type': 'delete_statement', 'children': ['29']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'other_weights'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'probability_of_i'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '43']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'picks'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sample_size'},{'id': '43', 'type': 'block', 'children': ['44', '57', '61', '118']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'permutations'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'permutations'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'other_weights'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'picks'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'permutation_probabilities'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'permutation'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'permutations'},{'id': '64', 'type': 'block', 'children': ['65', '69', '73', '90', '97', '111']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pick_probabilities'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pick_weight_sum'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'weights_sum'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pick'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'permutation'},{'id': '76', 'type': 'block', 'children': ['77', '86']},{'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': 'pick_probabilities'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '/'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pick'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pick_weight_sum'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'augmented_assignment', 'children': ['88', '89'], 'value': '-='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'pick_weight_sum'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pick'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'augmented_assignment', 'children': ['92', '93'], 'value': '+='},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pick_probabilities'},{'id': '93', 'type': 'list', 'children': ['94'], 'value': '[weight_i / pick_weight_sum]'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '/'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'weight_i'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pick_weight_sum'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'permutation_probability'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '102', 'type': 'argument_list', 'children': ['103', '110']},{'id': '103', 'type': 'lambda', 'children': ['104', '107']},{'id': '104', 'type': 'lambda_parameters', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '*'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pick_probabilities'},{'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': 'permutation_probabilities'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'permutation_probability'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '+='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'probability_of_i'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'permutation_probabilities'},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'probability_of_i'} | def p(i, sample_size, weights):
weight_i = weights[i]
weights_sum = sum(weights)
other_weights = list(weights)
del other_weights[i]
probability_of_i = 0
for picks in range(0, sample_size):
permutations = list(itertools.permutations(other_weights, picks))
permutation_probabilities = []
for permutation in permutations:
pick_probabilities = []
pick_weight_sum = weights_sum
for pick in permutation:
pick_probabilities.append(pick / pick_weight_sum)
pick_weight_sum -= pick
pick_probabilities += [weight_i / pick_weight_sum]
permutation_probability = reduce(
lambda x, y: x * y, pick_probabilities
)
permutation_probabilities.append(permutation_probability)
probability_of_i += sum(permutation_probabilities)
return probability_of_i |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'diff_to_html'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '6', 'type': 'block', 'children': ['7', '11', '17', '63', '76', '139', '152', '256', '269', '332']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'changes'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'if_statement', 'children': ['12', '14']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "''"},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']},{'id': '18', 'type': 'function_name', 'children': [], 'value': '_frame'},{'id': '19', 'type': 'parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '21', 'type': 'block', 'children': ['22', '58']},{'id': '22', 'type': 'if_statement', 'children': ['23', '32', '37']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '29'], 'value': 'and'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'},{'id': '30', 'type': 'string', 'children': [], 'value': "'_str'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '36', 'type': 'string', 'children': [], 'value': "'_str'"},{'id': '37', 'type': 'elif_clause', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', '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', '55']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'additions'"},{'id': '75', 'type': 'dictionary', 'children': []},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '79', 'type': 'block', 'children': ['80', '91', '114', '132']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '89', 'type': 'string', 'children': [], 'value': "'additions'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '91', 'type': 'if_statement', 'children': ['92', '97']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "', '"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'list_comprehension', 'children': ['107', '111']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '117', 'type': 'call', 'children': ['118', '125']},{'id': '118', 'type': 'attribute', 'children': ['119', '124']},{'id': '119', 'type': 'subscript', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_templates'},{'id': '123', 'type': 'string', 'children': [], 'value': "'add'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '125', 'type': 'argument_list', 'children': ['126', '129']},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'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': 'changes'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'updates'"},{'id': '151', 'type': 'dictionary', 'children': []},{'id': '152', 'type': 'for_statement', 'children': ['153', '154', '155']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '155', 'type': 'block', 'children': ['156', '169', '192', '205', '228', '249']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '168']},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '166', 'type': 'string', 'children': [], 'value': "'updates'"},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'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': 'original_value'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "', '"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'list_comprehension', 'children': ['185', '189']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'subscript', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '202', 'type': 'string', 'children': [], 'value': "'updates'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'if_statement', 'children': ['206', '211']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': "', '"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'list_comprehension', 'children': ['221', '225']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '225', 'type': 'for_in_clause', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '231', 'type': 'call', 'children': ['232', '239']},{'id': '232', 'type': 'attribute', 'children': ['233', '238']},{'id': '233', 'type': 'subscript', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '236', 'type': 'identifier', 'children': [], 'value': '_templates'},{'id': '237', 'type': 'string', 'children': [], 'value': "'update'"},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '239', 'type': 'argument_list', 'children': ['240', '243', '246']},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'changes'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': "'deletions'"},{'id': '268', 'type': 'dictionary', 'children': []},{'id': '269', 'type': 'for_statement', 'children': ['270', '271', '272']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '272', 'type': 'block', 'children': ['273', '284', '307', '325']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'subscript', 'children': ['280', '283']},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '282', 'type': 'string', 'children': [], 'value': "'deletions'"},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '284', 'type': 'if_statement', 'children': ['285', '290']},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'string', 'children': [], 'value': "', '"},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'list_comprehension', 'children': ['300', '304']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': '_frame'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '304', 'type': 'for_in_clause', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '310', 'type': 'call', 'children': ['311', '318']},{'id': '311', 'type': 'attribute', 'children': ['312', '317']},{'id': '312', 'type': 'subscript', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '315', 'type': 'identifier', 'children': [], 'value': '_templates'},{'id': '316', 'type': 'string', 'children': [], 'value': "'delete'"},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '318', 'type': 'argument_list', 'children': ['319', '322']},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'original_value'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'changes'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'change'},{'id': '332', 'type': 'return_statement', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'changes'} | def diff_to_html(cls, details):
changes = []
if not details:
return ''
def _frame(value):
if isinstance(value, dict) and '_str' in value:
return value['_str']
elif isinstance(value, list):
return ', '.join([_frame(v) for v in value])
return str(value)
fields = sorted(details.get('additions', {}))
for field in fields:
new_value = _frame(details['additions'][field])
if isinstance(new_value, list):
new_value = ', '.join([_frame(v) for v in new_value])
change = cls._templates['add'].format(
field=field,
new_value=new_value
)
changes.append(change)
fields = sorted(details.get('updates', {}))
for field in fields:
original_value = _frame(details['updates'][field][0])
if isinstance(original_value, list):
original_value = ', '.join([_frame(v) for v in original_value])
new_value = _frame(details['updates'][field][1])
if isinstance(new_value, list):
new_value = ', '.join([_frame(v) for v in new_value])
change = cls._templates['update'].format(
field=field,
original_value=original_value,
new_value=new_value
)
changes.append(change)
fields = sorted(details.get('deletions', {}))
for field in fields:
original_value = _frame(details['deletions'][field])
if isinstance(original_value, list):
original_value = ', '.join([_frame(v) for v in original_value])
change = cls._templates['delete'].format(
field=field,
original_value=original_value
)
changes.append(change)
return '\n'.join(changes) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'SortBy'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '6', 'type': 'block', 'children': ['7', '11', '54']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '24', '41']},{'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': 'q'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'.desc'"},{'id': '24', 'type': 'block', 'children': ['25']},{'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': 'sort'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'tuple', 'children': ['32', '40']},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '36', 'type': 'slice', 'children': ['37', '38']},{'id': '37', 'type': 'colon', 'children': []},{'id': '38', 'type': 'unary_operator', 'children': ['39'], 'value': '-'},{'id': '39', 'type': 'integer', 'children': [], 'value': '5'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'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': 'sort'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'tuple', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_path'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'} | def SortBy(*qs):
sort = []
for q in qs:
if q._path.endswith('.desc'):
sort.append((q._path[:-5], DESCENDING))
else:
sort.append((q._path, ASCENDING))
return sort |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'refresh'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '9', '51', '65', '72', '141']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'id': '8', 'type': 'list', 'children': [], 'value': '[]'},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '16']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'traceback'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'extract_stack'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '38']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '26', 'type': 'argument_list', 'children': ['27', '37']},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'OVERRIDE_FILE'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'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': 'override_files'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'OVERRIDE_FILE'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'delete_statement', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'OVERRIDE_FILE'},{'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': 'override_files'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'OVERRIDE_FILE'},{'id': '72', 'type': 'function_definition', 'children': ['73', '74', '76']},{'id': '73', 'type': 'function_name', 'children': [], 'value': 'import_path'},{'id': '74', 'type': 'parameters', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'block', 'children': ['77', '103', '107', '119', '130', '139']},{'id': '77', 'type': 'if_statement', 'children': ['78', '86']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '<'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '82', 'type': 'tuple', 'children': ['83', '84', '85']},{'id': '83', 'type': 'integer', 'children': [], 'value': '3'},{'id': '84', 'type': 'integer', 'children': [], 'value': '5'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'block', 'children': ['87', '93']},{'id': '87', 'type': 'import_from_statement', 'children': ['88', '91']},{'id': '88', 'type': 'dotted_name', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'machinery'},{'id': '91', 'type': 'dotted_name', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'SourceFileLoader'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '102']},{'id': '95', 'type': 'attribute', 'children': ['96', '101']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'SourceFileLoader'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'load_module'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'import_statement', 'children': ['104']},{'id': '104', 'type': 'dotted_name', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'spec_from_file_location'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '122', 'type': 'call', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'module_from_spec'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'exec_module'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'override_file'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'override_files'},{'id': '144', 'type': 'block', 'children': ['145', '157', '164']},{'id': '145', 'type': 'if_statement', 'children': ['146', '155']},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'override_file'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'continue_statement', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'import_path'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'override_file'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'globals'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'dictionary_comprehension', 'children': ['173', '180', '186']},{'id': '173', 'type': 'pair', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '186', 'type': 'if_clause', 'children': ['187']},{'id': '187', 'type': 'not_operator', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'string', 'children': [], 'value': '"__"'} | def refresh():
override_files = []
for stack in traceback.extract_stack():
f = os.path.join(os.path.dirname(stack[0]), OVERRIDE_FILE)
if f not in override_files:
override_files.insert(0, f)
if OVERRIDE_FILE in override_files:
del override_files[override_files.index(OVERRIDE_FILE)]
override_files.append(OVERRIDE_FILE)
def import_path(path):
if sys.version_info < (3, 5, 0):
from importlib.machinery import SourceFileLoader
return SourceFileLoader(__name__, path).load_module()
import importlib.util
spec = importlib.util.spec_from_file_location(__name__, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
for override_file in override_files:
if not os.path.isfile(override_file):
continue
mod = import_path(override_file)
globals().update({n: getattr(mod, n) for n in dir(mod) if not n.startswith("__")}) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup'},{'id': '3', 'type': 'parameters', 'children': ['4', '14', '18']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Union'},{'id': '9', 'type': 'type_parameter', 'children': ['10', '12']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'typed_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'structured'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '18', 'type': 'typed_default_parameter', 'children': ['19', '20', '22']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '26', '30', '46', '89', '112', '118', '125', '189', '197', '204']},{'id': '24', 'type': 'global_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'logs_are_structured'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'logs_are_structured'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'structured'},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_nameToLevel'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '46', 'type': 'function_definition', 'children': ['47', '48', '50']},{'id': '47', 'type': 'function_name', 'children': [], 'value': 'ensure_utf8_stream'},{'id': '48', 'type': 'parameters', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '50', 'type': 'block', 'children': ['51', '87']},{'id': '51', 'type': 'if_statement', 'children': ['52', '66']},{'id': '52', 'type': 'boolean_operator', 'children': ['53', '61'], 'value': 'and'},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '65', 'type': 'string', 'children': [], 'value': '"buffer"'},{'id': '66', 'type': 'block', 'children': ['67', '81']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '70', 'type': 'call', 'children': ['71', '77']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'getwriter'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '86', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '98']},{'id': '91', 'type': 'pattern_list', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '98', 'type': 'generator_expression', 'children': ['99', '103']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ensure_utf8_stream'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '105', 'type': 'tuple', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'basicConfig'},{'id': '117', 'type': 'argument_list', 'children': []},{'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': 'logging'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'setLogRecordFactory'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'NumpyLogRecord'},{'id': '125', 'type': 'if_statement', 'children': ['126', '138']},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '130'], 'value': 'and'},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '138', 'type': 'block', 'children': ['139', '159']},{'id': '139', 'type': 'with_statement', 'children': ['140', '149']},{'id': '140', 'type': 'with_clause', 'children': ['141']},{'id': '141', 'type': 'with_item', 'children': ['142']},{'id': '142', 'type': 'as_pattern', 'children': ['143', '147']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'config_path'},{'id': '147', 'type': 'as_pattern_target', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'safe_load'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '159', 'type': 'for_statement', 'children': ['160', '163', '168']},{'id': '160', 'type': 'pattern_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '179']},{'id': '171', 'type': 'attribute', 'children': ['172', '178']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '186']},{'id': '181', 'type': 'attribute', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '_nameToLevel'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '204', 'type': 'if_statement', 'children': ['205', '207', '241']},{'id': '205', 'type': 'not_operator', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'structured'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'if_statement', 'children': ['209', '223']},{'id': '209', 'type': 'boolean_operator', 'children': ['210', '216'], 'value': 'and'},{'id': '210', 'type': 'not_operator', 'children': ['211']},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'isatty'},{'id': '222', 'type': 'argument_list', 'children': []},{'id': '223', 'type': 'block', 'children': ['224', '232']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '231', 'type': 'integer', 'children': [], 'value': '0'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'setFormatter'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'AwesomeFormatter'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '250']},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'handlers'},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'StructuredHandler'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'level'} | def setup(level: Union[str, int], structured: bool, config_path: str = None):
global logs_are_structured
logs_are_structured = structured
if not isinstance(level, int):
level = logging._nameToLevel[level]
def ensure_utf8_stream(stream):
if not isinstance(stream, io.StringIO) and hasattr(stream, "buffer"):
stream = codecs.getwriter("utf-8")(stream.buffer)
stream.encoding = "utf-8"
return stream
sys.stdout, sys.stderr = (ensure_utf8_stream(s)
for s in (sys.stdout, sys.stderr))
logging.basicConfig()
logging.setLogRecordFactory(NumpyLogRecord)
if config_path is not None and os.path.isfile(config_path):
with open(config_path) as fh:
config = yaml.safe_load(fh)
for key, val in config.items():
logging.getLogger(key).setLevel(logging._nameToLevel.get(val, level))
root = logging.getLogger()
root.setLevel(level)
if not structured:
if not sys.stdin.closed and sys.stdout.isatty():
handler = root.handlers[0]
handler.setFormatter(AwesomeFormatter())
else:
root.handlers[0] = StructuredHandler(level) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getMessage'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '39', '148']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16', '28']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'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': 'msg'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'array2string'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '43', 'type': 'block', 'children': ['44', '50', '142']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'a2s'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'array2string'},{'id': '50', 'type': 'if_statement', 'children': ['51', '58', '90', '124']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '62', 'type': 'dictionary_comprehension', 'children': ['63', '79']},{'id': '63', 'type': 'pair', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '65', 'type': '()', 'children': ['66']},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '71', '78'], 'value': 'if'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'a2s'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'v'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '79', 'type': 'for_in_clause', 'children': ['80', '83']},{'id': '80', 'type': 'tuple_pattern', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'elif_clause', 'children': ['91', '98']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'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': 'args'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '104', 'type': 'generator_expression', 'children': ['105', '119']},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'conditional_expression', 'children': ['107', '111', '118'], 'value': 'if'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'a2s'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '%'},{'id': '131', 'type': 'string', 'children': [], 'value': '"Unexpected input \'%s\' with type \'%s\'"'},{'id': '132', 'type': 'tuple', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'msg'} | def getMessage(self):
if isinstance(self.msg, numpy.ndarray):
msg = self.array2string(self.msg)
else:
msg = str(self.msg)
if self.args:
a2s = self.array2string
if isinstance(self.args, Dict):
args = {k: (a2s(v) if isinstance(v, numpy.ndarray) else v)
for (k, v) in self.args.items()}
elif isinstance(self.args, Sequence):
args = tuple((a2s(a) if isinstance(a, numpy.ndarray) else a)
for a in self.args)
else:
raise TypeError("Unexpected input '%s' with type '%s'" % (self.args,
type(self.args)))
msg = msg % args
return msg |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'toposorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '6', 'type': 'block', 'children': ['7', '14', '21', '51', '62', '66', '138']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'incoming'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'outgoing'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '24', 'type': 'block', 'children': ['25', '38']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'incoming'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'to_id'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'from_id'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '47']},{'id': '40', 'type': 'attribute', 'children': ['41', '46']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'outgoing'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'from_id'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'to_id'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'working_set'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '65', 'type': 'list', 'children': [], 'value': '[]'},{'id': '66', 'type': 'while_statement', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'working_set'},{'id': '68', 'type': 'block', 'children': ['69', '73', '118', '134']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '72', 'type': 'list', 'children': [], 'value': '[]'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'working_set'},{'id': '76', 'type': 'block', 'children': ['77', '92', '99']},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'incoming'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '83', 'type': 'block', 'children': ['84', '91']},{'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': 'remaining'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '91', 'type': 'continue_statement', 'children': []},{'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': 'results'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '106']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'outgoing'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'id'},{'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': 'incoming'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '118', 'type': 'if_statement', 'children': ['119', '128']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '=='},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'working_set'},{'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': 'remaining'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': '"Cycle detected"'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'working_set'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'results'} | def toposorted(nodes, edges):
incoming = defaultdict(set)
outgoing = defaultdict(set)
for edge in edges:
incoming[edge.to_id].add(edge.from_id)
outgoing[edge.from_id].add(edge.to_id)
working_set = list(nodes.values())
results = []
while working_set:
remaining = []
for node in working_set:
if incoming[node.id]:
remaining.append(node)
continue
results.append(node)
for child in outgoing[node.id]:
incoming[child].remove(node.id)
if len(working_set) == len(remaining):
raise Exception("Cycle detected")
working_set = remaining
return results |
{'id': '0', 'type': 'ERROR', 'children': ['1', '2', '5', '7', '41', '51', '63', '74', '77', '303', '306', '324', '334', '335']},{'id': '1', 'type': 'identifier', 'children': [], 'value': 'proc'},{'id': '2', 'type': 'parameters', 'children': ['3', '4']},{'id': '3', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'string', 'children': [], 'value': "'''Process calculated structures'''"},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'calc_reader'},{'id': '9', 'type': 'parameters', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '12', 'type': 'block', 'children': ['13', '32']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '19', 'type': 'argument_list', 'children': ['20', '26', '29']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'Reading: {:<60s}\\r'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '28', 'type': 'False', 'children': []},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ase'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '44', 'type': 'subscript', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '50', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'calc_reader'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'calc'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'calc'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '63', 'type': 'if_statement', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "''"},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '=='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '76', 'type': 'string', 'children': [], 'value': "'cij'"},{'id': '77', 'type': 'block', 'children': ['78', '96', '108', '112', '256', '299']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'elastic'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_elastic_tensor'},{'id': '85', 'type': 'argument_list', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '93', 'type': 'slice', 'children': ['94', '95']},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'msv'},{'id': '99', 'type': 'call', 'children': ['100', '107']},{'id': '100', 'type': 'attribute', 'children': ['101', '106']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'integer', 'children': [], 'value': '3'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'eps'},{'id': '111', 'type': 'float', 'children': [], 'value': '1e-4'},{'id': '112', 'type': 'if_statement', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '114', 'type': 'block', 'children': ['115', '124', '153', '181', '186', '216', '221', '247']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'},{'id': '120', 'type': 'string', 'children': [], 'value': "'Cij solution\\n'"},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '*'},{'id': '122', 'type': 'integer', 'children': [], 'value': '30'},{'id': '123', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "' Solution rank: {:2d}{}'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '132', 'type': 'argument_list', 'children': ['133', '138']},{'id': '133', 'type': 'subscript', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'integer', 'children': [], 'value': '2'},{'id': '138', 'type': 'conditional_expression', 'children': ['139', '140', '152'], 'value': 'if'},{'id': '139', 'type': 'string', 'children': [], 'value': "' (undetermined)'"},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '146'], 'value': '<'},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'integer', 'children': [], 'value': '2'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'string', 'children': [], 'value': "''"},{'id': '153', 'type': 'if_statement', 'children': ['154', '166']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '160'], 'value': '=='},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'integer', 'children': [], 'value': '2'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': "' Square of residuals: {:7.2g}'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "' Relative singular values:'"},{'id': '186', 'type': 'for_statement', 'children': ['187', '188', '195']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '188', 'type': 'binary_operator', 'children': ['189', '194'], 'value': '/'},{'id': '189', 'type': 'subscript', 'children': ['190', '193']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'integer', 'children': [], 'value': '3'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'msv'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '199', 'type': 'argument_list', 'children': ['200', '213']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "'{:7.4f}{}'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '206', 'type': 'conditional_expression', 'children': ['207', '208', '212'], 'value': 'if'},{'id': '207', 'type': 'string', 'children': [], 'value': "'* '"},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '211'], 'value': '<'},{'id': '209', 'type': '()', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'eps'},{'id': '212', 'type': 'string', 'children': [], 'value': "' '"},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '215', 'type': 'False', 'children': []},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': "'\\n\\nElastic tensor (GPa):'"},{'id': '221', 'type': 'for_statement', 'children': ['222', '223', '233']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'dsc'},{'id': '223', 'type': 'call', 'children': ['224', '229']},{'id': '224', 'type': 'attribute', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'elastic'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'elastic'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'get_cij_order'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '237', 'type': 'argument_list', 'children': ['238', '244']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': "'{: >7s} '"},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'dsc'},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '246', 'type': 'False', 'children': []},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '+'},{'id': '252', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '*'},{'id': '254', 'type': 'integer', 'children': [], 'value': '30'},{'id': '255', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '256', 'type': 'for_statement', 'children': ['257', '260', '273']},{'id': '257', 'type': 'pattern_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '262', 'type': 'argument_list', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '265', 'type': 'integer', 'children': [], 'value': '0'},{'id': '266', 'type': 'binary_operator', 'children': ['267', '272'], 'value': '/'},{'id': '267', 'type': 'subscript', 'children': ['268', '271']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'cij'},{'id': '270', 'type': 'integer', 'children': [], 'value': '1'},{'id': '271', 'type': 'integer', 'children': [], 'value': '3'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'msv'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '277', 'type': 'argument_list', 'children': ['278', '296']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': "'{:7.2f}{}'"},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '282', 'type': 'argument_list', 'children': ['283', '290']},{'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '/'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '285', 'type': 'attribute', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'ase'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'GPa'},{'id': '290', 'type': 'conditional_expression', 'children': ['291', '292', '295'], 'value': 'if'},{'id': '291', 'type': 'string', 'children': [], 'value': "'* '"},{'id': '292', 'type': 'comparison_operator', 'children': ['293', '294'], 'value': '<'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'sv'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'eps'},{'id': '295', 'type': 'string', 'children': [], 'value': "' '"},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'nl'},{'id': '298', 'type': 'False', 'children': []},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '302', 'type': 'argument_list', 'children': []},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': '=='},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '305', 'type': 'string', 'children': [], 'value': "'eos'"},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'eos'},{'id': '309', 'type': 'call', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'elastic'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'get_BM_EOS'},{'id': '313', 'type': 'argument_list', 'children': ['314', '317']},{'id': '314', 'type': 'subscript', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '316', 'type': 'integer', 'children': [], 'value': '0'},{'id': '317', 'type': 'keyword_argument', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '319', 'type': 'subscript', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'systems'},{'id': '321', 'type': 'slice', 'children': ['322', '323']},{'id': '322', 'type': 'integer', 'children': [], 'value': '1'},{'id': '323', 'type': 'colon', 'children': []},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'augmented_assignment', 'children': ['326', '329'], 'value': '/='},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'eos'},{'id': '328', 'type': 'integer', 'children': [], 'value': '1'},{'id': '329', 'type': 'attribute', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'ase'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'GPa'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'echo'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'binary_operator', 'children': ['340', '347', '349', '351'], 'value': '%'},{'id': '340', 'type': 'binary_operator', 'children': ['341', '344', '346'], 'value': '%'},{'id': '341', 'type': 'binary_operator', 'children': ['342', '343'], 'value': '%'},{'id': '342', 'type': 'string', 'children': [], 'value': "'\n echo('"},{'id': '343', 'type': 'float', 'children': [], 'value': '7.2'},{'id': '344', 'type': 'ERROR', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '346', 'type': 'float', 'children': [], 'value': '7.2'},{'id': '347', 'type': 'ERROR', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '349', 'type': 'ERROR', 'children': ['350']},{'id': '350', 'type': 'float', 'children': [], 'value': '7.2'},{'id': '351', 'type': 'call', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'eos'} | def proc(ctx, files):
'''Process calculated structures'''
def calc_reader(fn, verb):
if verb:
echo('Reading: {:<60s}\r'.format(fn), nl=False, err=True)
return ase.io.read(fn)
action = ctx.parent.params['action']
systems = [calc_reader(calc, verbose) for calc in files]
if verbose :
echo('', err=True)
if action == 'cij':
cij = elastic.get_elastic_tensor(systems[0], systems=systems[1:])
msv = cij[1][3].max()
eps = 1e-4
if verbose:
echo('Cij solution\n'+30*'-')
echo(' Solution rank: {:2d}{}'.format(
cij[1][2],
' (undetermined)' if cij[1][2] < len(cij[0]) else ''))
if cij[1][2] == len(cij[0]):
echo(' Square of residuals: {:7.2g}'.format(cij[1][1]))
echo(' Relative singular values:')
for sv in cij[1][3]/msv:
echo('{:7.4f}{}'.format(
sv, '* ' if (sv) < eps else ' '), nl=False)
echo('\n\nElastic tensor (GPa):')
for dsc in elastic.elastic.get_cij_order(systems[0]):
echo('{: >7s} '.format(dsc), nl=False)
echo('\n'+30*'-')
for c, sv in zip(cij[0], cij[1][3]/msv):
echo('{:7.2f}{}'.format(
c/ase.units.GPa, '* ' if sv < eps else ' '), nl=False)
echo()
elif action == 'eos':
eos = elastic.get_BM_EOS(systems[0], systems=systems[1:])
eos[1] /= ase.units.GPa
if verbose:
echo('
echo(' %7.2f %7.2f %7.2f' % tuple(eos)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sample'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tenure'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'scale_factor'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '17', 'type': 'integer', 'children': [], 'value': '20'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'num_reads'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'id': '21', 'type': 'block', 'children': ['22', '113', '134', '156', '169', '184', '197', '207', '218', '222', '226', '312', '331', '343']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26', '107']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '42', '57', '79']},{'id': '27', 'type': 'if_statement', 'children': ['28', '36']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dimod'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'SampleSet'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': '"\'init_solution\' should be a \'dimod.SampleSet\' instance"'},{'id': '42', 'type': 'if_statement', 'children': ['43', '51']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '50'], 'value': '<'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'raise_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': '"\'init_solution\' should contain at least one sample"'},{'id': '57', 'type': 'if_statement', 'children': ['58', '73']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '69'], 'value': '!='},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'attribute', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'raise_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': '"\'init_solution\' sample dimension different from BQM"'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'init_sample'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_bqm_sample_to_tabu_sample'},{'id': '86', 'type': 'argument_list', 'children': ['87', '104']},{'id': '87', 'type': 'attribute', 'children': ['88', '103']},{'id': '88', 'type': 'subscript', 'children': ['89', '102']},{'id': '89', 'type': 'attribute', 'children': ['90', '101']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'init_solution'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'change_vartype'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dimod'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'BINARY'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '100', 'type': 'False', 'children': []},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'init_sample'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '116']},{'id': '114', 'type': 'not_operator', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', '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': 'dimod'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'SampleSet'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'from_samples'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '129']},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'vartype'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'vartype'},{'id': '134', 'type': 'if_statement', 'children': ['135', '138']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'tenure'},{'id': '137', 'type': 'None', 'children': []},{'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': 'tenure'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '144', 'type': 'argument_list', 'children': ['145', '155']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'integer', 'children': [], 'value': '20'},{'id': '149', 'type': 'binary_operator', 'children': ['150', '154'], 'value': '//'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '154', 'type': 'integer', 'children': [], 'value': '4'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'if_statement', 'children': ['157', '163']},{'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': 'tenure'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'raise_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'string', 'children': [], 'value': '"\'tenure\' should be an integer in range [0, num_vars - 1]"'},{'id': '169', 'type': 'if_statement', 'children': ['170', '178']},{'id': '170', 'type': 'not_operator', 'children': ['171']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173', '174'], 'value': '<='},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'tenure'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'string', 'children': [], 'value': '"\'tenure\' should be an integer in range [0, num_vars - 1]"'},{'id': '184', 'type': 'if_statement', 'children': ['185', '191']},{'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': 'num_reads'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'raise_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'string', 'children': [], 'value': '"\'num_reads\' should be a positive integer"'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '<'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'num_reads'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'raise_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'string', 'children': [], 'value': '"\'num_reads\' should be a positive integer"'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'qubo'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_bqm_to_tabu_qubo'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '221', 'type': 'list', 'children': [], 'value': '[]'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'energies'},{'id': '225', 'type': 'list', 'children': [], 'value': '[]'},{'id': '226', 'type': 'for_statement', 'children': ['227', '228', '232']},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'num_reads'},{'id': '232', 'type': 'block', 'children': ['233', '257', '268', '287', '298', '305']},{'id': '233', 'type': 'if_statement', 'children': ['234', '237']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': 'is'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'init_sample'},{'id': '236', 'type': 'None', 'children': []},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'init_sample'},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_bqm_sample_to_tabu_sample'},{'id': '245', 'type': 'argument_list', 'children': ['246', '254']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '249', 'type': 'identifier', 'children': [], 'value': '_random_sample'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'TabuSearch'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264', '265', '266', '267']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'qubo'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'init_sample'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'tenure'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'scale_factor'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_tabu_sample_to_bqm_sample'},{'id': '275', 'type': 'argument_list', 'children': ['276', '284']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'bestSolution'},{'id': '283', 'type': 'argument_list', 'children': []},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '290', 'type': 'call', 'children': ['291', '296']},{'id': '291', 'type': 'attribute', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'sample'},{'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': 'samples'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'energies'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'dimod'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'SampleSet'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'from_samples'},{'id': '321', 'type': 'argument_list', 'children': ['322', '323', '326']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'energies'},{'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'vartype'},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'dimod'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'BINARY'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'change_vartype'},{'id': '336', 'type': 'argument_list', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'bqm'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'vartype'},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '342', 'type': 'True', 'children': []},{'id': '343', 'type': 'return_statement', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'response'} | def sample(self, bqm, init_solution=None, tenure=None, scale_factor=1, timeout=20, num_reads=1):
if init_solution is not None:
if not isinstance(init_solution, dimod.SampleSet):
raise TypeError("'init_solution' should be a 'dimod.SampleSet' instance")
if len(init_solution.record) < 1:
raise ValueError("'init_solution' should contain at least one sample")
if len(init_solution.record[0].sample) != len(bqm):
raise ValueError("'init_solution' sample dimension different from BQM")
init_sample = self._bqm_sample_to_tabu_sample(
init_solution.change_vartype(dimod.BINARY, inplace=False).record[0].sample, bqm.binary)
else:
init_sample = None
if not bqm:
return dimod.SampleSet.from_samples([], energy=0, vartype=bqm.vartype)
if tenure is None:
tenure = max(min(20, len(bqm) // 4), 0)
if not isinstance(tenure, int):
raise TypeError("'tenure' should be an integer in range [0, num_vars - 1]")
if not 0 <= tenure < len(bqm):
raise ValueError("'tenure' should be an integer in range [0, num_vars - 1]")
if not isinstance(num_reads, int):
raise TypeError("'num_reads' should be a positive integer")
if num_reads < 1:
raise ValueError("'num_reads' should be a positive integer")
qubo = self._bqm_to_tabu_qubo(bqm.binary)
samples = []
energies = []
for _ in range(num_reads):
if init_sample is None:
init_sample = self._bqm_sample_to_tabu_sample(self._random_sample(bqm.binary), bqm.binary)
r = TabuSearch(qubo, init_sample, tenure, scale_factor, timeout)
sample = self._tabu_sample_to_bqm_sample(list(r.bestSolution()), bqm.binary)
energy = bqm.binary.energy(sample)
samples.append(sample)
energies.append(energy)
response = dimod.SampleSet.from_samples(
samples, energy=energies, vartype=dimod.BINARY)
response.change_vartype(bqm.vartype, inplace=True)
return response |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mmi_to_raster'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'force_flag'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'USE_ASCII'},{'id': '11', 'type': 'block', 'children': ['12', '19', '28', '73', '89', '247', '254', '299', '307', '315']},{'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']},{'id': '18', 'type': 'string', 'children': [], 'value': "'mmi_to_raster requested.'"},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'USE_ASCII'},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '53']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'algorithm_name'},{'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': 'tif_path'},{'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': 'os'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '42', 'type': 'argument_list', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'},{'id': '47', 'type': 'string', 'children': [], 'value': "'%s-%s.tif'"},{'id': '48', 'type': 'tuple', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'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': 'tif_path'},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '64', 'type': 'argument_list', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'},{'id': '69', 'type': 'string', 'children': [], 'value': "'%s.tif'"},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '73', 'type': 'if_statement', 'children': ['74', '86']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '83'], 'value': 'and'},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tif_path'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'force_flag'},{'id': '85', 'type': 'True', 'children': []},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tif_path'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93', '143']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'USE_ASCII'},{'id': '93', 'type': 'block', 'children': ['94', '103', '127', '136']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ascii_path'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mmi_to_ascii'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'True', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '112'], 'value': '%'},{'id': '108', 'type': '()', 'children': ['109']},{'id': '109', 'type': 'concatenated_string', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'%(gdal_translate)s -a_srs EPSG:4326 '"},{'id': '111', 'type': 'string', 'children': [], 'value': '\'"%(ascii)s" "%(tif)s"\''},{'id': '112', 'type': 'dictionary', 'children': ['113', '121', '124']},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'gdal_translate'"},{'id': '115', 'type': 'subscript', 'children': ['116', '120']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'which'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'gdal_translate'"},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ascii_path'},{'id': '124', 'type': 'pair', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'tif'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tif_path'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'},{'id': '134', 'type': 'string', 'children': [], 'value': "'Created this gdal command:\\n%s'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'command'},{'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': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': '_run_command'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145', '154', '163', '222', '231', '238']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'vrt_path'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'mmi_to_vrt'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'force_flag'},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'INVDIST'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '162', 'type': 'string', 'children': [], 'value': "'invdist:power=2.0:smoothing=1.0'"},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '166', 'type': '()', 'children': ['167']},{'id': '167', 'type': 'binary_operator', 'children': ['168', '174'], 'value': '%'},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'concatenated_string', 'children': ['170', '171', '172', '173']},{'id': '170', 'type': 'string', 'children': [], 'value': '\'%(gdal_grid)s -a %(alg)s -zfield "mmi" -txe %(xMin)s \''},{'id': '171', 'type': 'string', 'children': [], 'value': "'%(xMax)s -tye %(yMin)s %(yMax)s -outsize %(dimX)i '"},{'id': '172', 'type': 'string', 'children': [], 'value': "'%(dimY)i -of GTiff -ot Float16 -a_srs EPSG:4326 -l mmi '"},{'id': '173', 'type': 'string', 'children': [], 'value': '\'"%(vrt)s" "%(tif)s"\''},{'id': '174', 'type': 'dictionary', 'children': ['175', '183', '186', '191', '196', '201', '206', '211', '216', '219']},{'id': '175', 'type': 'pair', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'gdal_grid'"},{'id': '177', 'type': 'subscript', 'children': ['178', '182']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'which'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': "'gdal_grid'"},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'pair', 'children': ['184', '185']},{'id': '184', 'type': 'string', 'children': [], 'value': "'alg'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '186', 'type': 'pair', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'xMin'"},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x_minimum'},{'id': '191', 'type': 'pair', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "'xMax'"},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'x_maximum'},{'id': '196', 'type': 'pair', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "'yMin'"},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'y_minimum'},{'id': '201', 'type': 'pair', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "'yMax'"},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'y_maximum'},{'id': '206', 'type': 'pair', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': "'dimX'"},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '211', 'type': 'pair', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': "'dimY'"},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '216', 'type': 'pair', 'children': ['217', '218']},{'id': '217', 'type': 'string', 'children': [], 'value': "'vrt'"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'vrt_path'},{'id': '219', 'type': 'pair', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'tif'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'tif_path'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '%'},{'id': '229', 'type': 'string', 'children': [], 'value': "'Created this gdal command:\\n%s'"},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_run_command'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'in'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'INVDIST'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '246', 'type': 'string', 'children': [], 'value': "'invdist'"},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'create_keyword_file'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '254', 'type': 'if_statement', 'children': ['255', '258', '279']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'algorithm_name'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'qml_path'},{'id': '262', 'type': 'call', 'children': ['263', '268']},{'id': '263', 'type': 'attribute', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '268', 'type': 'argument_list', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'},{'id': '273', 'type': 'string', 'children': [], 'value': "'%s-%s.qml'"},{'id': '274', 'type': 'tuple', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'qml_path'},{'id': '284', 'type': 'call', 'children': ['285', '290']},{'id': '285', 'type': 'attribute', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '290', 'type': 'argument_list', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'},{'id': '295', 'type': 'string', 'children': [], 'value': "'%s.qml'"},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'qml_source_path'},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'resources_path'},{'id': '304', 'type': 'argument_list', 'children': ['305', '306']},{'id': '305', 'type': 'string', 'children': [], 'value': "'converter_data'"},{'id': '306', 'type': 'string', 'children': [], 'value': "'mmi.qml'"},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'copyfile'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'qml_source_path'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'qml_path'},{'id': '315', 'type': 'return_statement', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'tif_path'} | def mmi_to_raster(self, force_flag=False, algorithm=USE_ASCII):
LOGGER.debug('mmi_to_raster requested.')
if algorithm is None:
algorithm = USE_ASCII
if self.algorithm_name:
tif_path = os.path.join(
self.output_dir, '%s-%s.tif' % (
self.output_basename, algorithm))
else:
tif_path = os.path.join(
self.output_dir, '%s.tif' % self.output_basename)
if os.path.exists(tif_path) and force_flag is not True:
return tif_path
if algorithm == USE_ASCII:
ascii_path = self.mmi_to_ascii(True)
command = (
(
'%(gdal_translate)s -a_srs EPSG:4326 '
'"%(ascii)s" "%(tif)s"'
) % {
'gdal_translate': which('gdal_translate')[0],
'ascii': ascii_path,
'tif': tif_path
}
)
LOGGER.info('Created this gdal command:\n%s' % command)
self._run_command(command)
else:
vrt_path = self.mmi_to_vrt(force_flag)
if INVDIST in algorithm:
algorithm = 'invdist:power=2.0:smoothing=1.0'
command = (
(
'%(gdal_grid)s -a %(alg)s -zfield "mmi" -txe %(xMin)s '
'%(xMax)s -tye %(yMin)s %(yMax)s -outsize %(dimX)i '
'%(dimY)i -of GTiff -ot Float16 -a_srs EPSG:4326 -l mmi '
'"%(vrt)s" "%(tif)s"'
) % {
'gdal_grid': which('gdal_grid')[0],
'alg': algorithm,
'xMin': self.x_minimum,
'xMax': self.x_maximum,
'yMin': self.y_minimum,
'yMax': self.y_maximum,
'dimX': self.columns,
'dimY': self.rows,
'vrt': vrt_path,
'tif': tif_path
}
)
LOGGER.info('Created this gdal command:\n%s' % command)
self._run_command(command)
if INVDIST in algorithm:
algorithm = 'invdist'
self.create_keyword_file(algorithm)
if self.algorithm_name:
qml_path = os.path.join(
self.output_dir, '%s-%s.qml' % (
self.output_basename, algorithm))
else:
qml_path = os.path.join(
self.output_dir, '%s.qml' % self.output_basename)
qml_source_path = resources_path('converter_data', 'mmi.qml')
shutil.copyfile(qml_source_path, qml_path)
return tif_path |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_keyword_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '6', 'type': 'block', 'children': ['7', '13', '20', '35', '42', '57', '61', '90', '190', '211', '215', '240', '251', '302', '347', '375', '381', '389', '401']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keyword_io'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'KeywordIO'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mmi_default_classes'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'default_classification_thresholds'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'earthquake_mmi_scale'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mmi_default_threshold'},{'id': '23', 'type': 'dictionary', 'children': ['24']},{'id': '24', 'type': 'pair', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'earthquake_mmi_scale'},{'id': '27', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '28', 'type': 'dictionary', 'children': ['29', '32']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'classes'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mmi_default_classes'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'generic_default_classes'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'default_classification_thresholds'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'generic_hazard_classes'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'generic_default_threshold'},{'id': '45', 'type': 'dictionary', 'children': ['46']},{'id': '46', 'type': 'pair', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'generic_hazard_classes'},{'id': '49', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '50', 'type': 'dictionary', 'children': ['51', '54']},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'active'"},{'id': '53', 'type': 'True', 'children': []},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'classes'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'generic_default_classes'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'threshold_keyword'},{'id': '60', 'type': 'dictionary', 'children': []},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'exposure_all'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '71', '80']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'earthquake_mmi_scale'},{'id': '70', 'type': 'string', 'children': [], 'value': "'exposures'"},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '79']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'threshold_keyword'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '78', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mmi_default_threshold'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'threshold_keyword'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '88', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'generic_default_threshold'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'extra_keywords'},{'id': '93', 'type': 'dictionary', 'children': ['94', '101', '108', '115', '122', '129', '136', '148', '155', '162', '169', '176', '183']},{'id': '94', 'type': 'pair', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_latitude'},{'id': '97', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'latitude'},{'id': '101', 'type': 'pair', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_longitude'},{'id': '104', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'longitude'},{'id': '108', 'type': 'pair', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_magnitude'},{'id': '111', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'magnitude'},{'id': '115', 'type': 'pair', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_depth'},{'id': '118', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '122', 'type': 'pair', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_description'},{'id': '125', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '129', 'type': 'pair', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_location'},{'id': '132', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '136', 'type': 'pair', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_event_time'},{'id': '139', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'string', 'children': [], 'value': "'%Y-%m-%dT%H:%M:%S'"},{'id': '148', 'type': 'pair', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_time_zone'},{'id': '151', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'time_zone'},{'id': '155', 'type': 'pair', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_x_minimum'},{'id': '158', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x_minimum'},{'id': '162', 'type': 'pair', 'children': ['163', '166']},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_x_maximum'},{'id': '165', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x_maximum'},{'id': '169', 'type': 'pair', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_y_minimum'},{'id': '172', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'y_minimum'},{'id': '176', 'type': 'pair', 'children': ['177', '180']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_y_maximum'},{'id': '179', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'y_maximum'},{'id': '183', 'type': 'pair', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'extra_keyword_earthquake_event_id'},{'id': '186', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'event_id'},{'id': '190', 'type': 'for_statement', 'children': ['191', '194', '204']},{'id': '191', 'type': 'pattern_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'extra_keywords'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'extra_keywords'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'empty_keys'},{'id': '214', 'type': 'list', 'children': [], 'value': '[]'},{'id': '215', 'type': 'for_statement', 'children': ['216', '219', '227']},{'id': '216', 'type': 'pattern_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'extra_keywords'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '232']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': 'is'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '231', 'type': 'None', 'children': []},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'empty_keys'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '240', 'type': 'for_statement', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'empty_key'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'empty_keys'},{'id': '243', 'type': 'block', 'children': ['244']},{'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': 'extra_keywords'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'empty_key'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '254', 'type': 'dictionary', 'children': ['255', '260', '265', '268', '273', '278', '283', '288', '293', '296', '299']},{'id': '255', 'type': 'pair', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': "'hazard'"},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'hazard_earthquake'},{'id': '259', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '260', 'type': 'pair', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': "'hazard_category'"},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'hazard_category_single_event'},{'id': '264', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '265', 'type': 'pair', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'keyword_version'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'inasafe_keyword_version'},{'id': '268', 'type': 'pair', 'children': ['269', '270']},{'id': '269', 'type': 'string', 'children': [], 'value': "'layer_geometry'"},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'layer_geometry_raster'},{'id': '272', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '273', 'type': 'pair', 'children': ['274', '275']},{'id': '274', 'type': 'string', 'children': [], 'value': "'layer_mode'"},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'layer_mode_continuous'},{'id': '277', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '278', 'type': 'pair', 'children': ['279', '280']},{'id': '279', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_hazard'},{'id': '282', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '283', 'type': 'pair', 'children': ['284', '285']},{'id': '284', 'type': 'string', 'children': [], 'value': "'continuous_hazard_unit'"},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'unit_mmi'},{'id': '287', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '288', 'type': 'pair', 'children': ['289', '290']},{'id': '289', 'type': 'string', 'children': [], 'value': "'classification'"},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'earthquake_mmi_scale'},{'id': '292', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '293', 'type': 'pair', 'children': ['294', '295']},{'id': '294', 'type': 'string', 'children': [], 'value': "'thresholds'"},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'threshold_keyword'},{'id': '296', 'type': 'pair', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': "'extra_keywords'"},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'extra_keywords'},{'id': '299', 'type': 'pair', 'children': ['300', '301']},{'id': '300', 'type': 'string', 'children': [], 'value': "'active_band'"},{'id': '301', 'type': 'integer', 'children': [], 'value': '1'},{'id': '302', 'type': 'if_statement', 'children': ['303', '306', '327']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'algorithm_name'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'layer_path'},{'id': '310', 'type': 'call', 'children': ['311', '316']},{'id': '311', 'type': 'attribute', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '316', 'type': 'argument_list', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '%'},{'id': '321', 'type': 'string', 'children': [], 'value': "'%s-%s.tif'"},{'id': '322', 'type': 'tuple', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'algorithm'},{'id': '327', 'type': 'else_clause', 'children': ['328']},{'id': '328', 'type': 'block', 'children': ['329']},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'assignment', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'layer_path'},{'id': '332', 'type': 'call', 'children': ['333', '338']},{'id': '333', 'type': 'attribute', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '338', 'type': 'argument_list', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'},{'id': '343', 'type': 'string', 'children': [], 'value': "'%s.tif'"},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '347', 'type': 'if_statement', 'children': ['348', '360', '367']},{'id': '348', 'type': 'comparison_operator', 'children': ['349', '359'], 'value': '=='},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '358']},{'id': '353', 'type': 'attribute', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '358', 'type': 'argument_list', 'children': []},{'id': '359', 'type': 'integer', 'children': [], 'value': '0'},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'keyword_title'},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'output_basename'},{'id': '367', 'type': 'else_clause', 'children': ['368']},{'id': '368', 'type': 'block', 'children': ['369']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'keyword_title'},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'assignment', 'children': ['377', '380']},{'id': '377', 'type': 'subscript', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '379', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'keyword_title'},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'assignment', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'hazard_layer'},{'id': '384', 'type': 'call', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'QgsRasterLayer'},{'id': '386', 'type': 'argument_list', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'layer_path'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'keyword_title'},{'id': '389', 'type': 'if_statement', 'children': ['390', '396']},{'id': '390', 'type': 'not_operator', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'hazard_layer'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'isValid'},{'id': '395', 'type': 'argument_list', 'children': []},{'id': '396', 'type': 'block', 'children': ['397']},{'id': '397', 'type': 'raise_statement', 'children': ['398']},{'id': '398', 'type': 'call', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'InvalidLayerError'},{'id': '400', 'type': 'argument_list', 'children': []},{'id': '401', 'type': 'expression_statement', 'children': ['402']},{'id': '402', 'type': 'call', 'children': ['403', '406']},{'id': '403', 'type': 'attribute', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'keyword_io'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'write_keywords'},{'id': '406', 'type': 'argument_list', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'hazard_layer'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'keywords'} | def create_keyword_file(self, algorithm):
keyword_io = KeywordIO()
mmi_default_classes = default_classification_thresholds(
earthquake_mmi_scale
)
mmi_default_threshold = {
earthquake_mmi_scale['key']: {
'active': True,
'classes': mmi_default_classes
}
}
generic_default_classes = default_classification_thresholds(
generic_hazard_classes
)
generic_default_threshold = {
generic_hazard_classes['key']: {
'active': True,
'classes': generic_default_classes
}
}
threshold_keyword = {}
for exposure in exposure_all:
if exposure in earthquake_mmi_scale['exposures']:
threshold_keyword[exposure['key']] = mmi_default_threshold
else:
threshold_keyword[
exposure['key']] = generic_default_threshold
extra_keywords = {
extra_keyword_earthquake_latitude['key']: self.latitude,
extra_keyword_earthquake_longitude['key']: self.longitude,
extra_keyword_earthquake_magnitude['key']: self.magnitude,
extra_keyword_earthquake_depth['key']: self.depth,
extra_keyword_earthquake_description['key']: self.description,
extra_keyword_earthquake_location['key']: self.location,
extra_keyword_earthquake_event_time['key']: self.time.strftime(
'%Y-%m-%dT%H:%M:%S'),
extra_keyword_time_zone['key']: self.time_zone,
extra_keyword_earthquake_x_minimum['key']: self.x_minimum,
extra_keyword_earthquake_x_maximum['key']: self.x_maximum,
extra_keyword_earthquake_y_minimum['key']: self.y_minimum,
extra_keyword_earthquake_y_maximum['key']: self.y_maximum,
extra_keyword_earthquake_event_id['key']: self.event_id
}
for key, value in list(self.extra_keywords.items()):
extra_keywords[key] = value
empty_keys = []
for key, value in list(extra_keywords.items()):
if value is None:
empty_keys.append(key)
for empty_key in empty_keys:
extra_keywords.pop(empty_key)
keywords = {
'hazard': hazard_earthquake['key'],
'hazard_category': hazard_category_single_event['key'],
'keyword_version': inasafe_keyword_version,
'layer_geometry': layer_geometry_raster['key'],
'layer_mode': layer_mode_continuous['key'],
'layer_purpose': layer_purpose_hazard['key'],
'continuous_hazard_unit': unit_mmi['key'],
'classification': earthquake_mmi_scale['key'],
'thresholds': threshold_keyword,
'extra_keywords': extra_keywords,
'active_band': 1
}
if self.algorithm_name:
layer_path = os.path.join(
self.output_dir, '%s-%s.tif' % (
self.output_basename, algorithm))
else:
layer_path = os.path.join(
self.output_dir, '%s.tif' % self.output_basename)
if len(self.title.strip()) == 0:
keyword_title = self.output_basename
else:
keyword_title = self.title
keywords['title'] = keyword_title
hazard_layer = QgsRasterLayer(layer_path, keyword_title)
if not hazard_layer.isValid():
raise InvalidLayerError()
keyword_io.write_keywords(hazard_layer, keywords) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_value_mapping'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'exposure_key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '24', '33', '83', '89', '136', '143', '147', '167', '171', '189', '201', '230', '238', '246']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '12', 'type': 'call', 'children': ['13', '20']},{'id': '13', 'type': 'attribute', 'children': ['14', '19']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lookupField'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'exposure_type_field'},{'id': '23', 'type': 'string', 'children': [], 'value': "'field_name'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'unique_exposure'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'uniqueValues'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '33', 'type': 'if_statement', 'children': ['34', '43', '70']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '40'], 'value': '=='},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '39', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_hazard'},{'id': '42', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '43', 'type': 'block', 'children': ['44', '60']},{'id': '44', 'type': 'if_statement', 'children': ['45', '47']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'exposure_key'},{'id': '47', 'type': 'block', 'children': ['48', '55']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tr'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'Hazard value mapping missing exposure key.'"},{'id': '55', 'type': 'raise_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'InvalidKeywordsForProcessingAlgorithm'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'active_thresholds_value_maps'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'exposure_key'},{'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': 'value_map'},{'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': 'layer'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'value_map'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '86']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '89', 'type': 'if_statement', 'children': ['90', '99', '126']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '96'], 'value': '=='},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '95', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_hazard'},{'id': '98', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '99', 'type': 'block', 'children': ['100', '116']},{'id': '100', 'type': 'if_statement', 'children': ['101', '103']},{'id': '101', 'type': 'not_operator', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'exposure_key'},{'id': '103', 'type': 'block', 'children': ['104', '111']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'tr'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'Hazard classification is missing exposure key.'"},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'InvalidKeywordsForProcessingAlgorithm'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'classification'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'active_classification'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'exposure_key'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'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': 'classification'},{'id': '131', 'type': 'subscript', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '135', 'type': 'string', 'children': [], 'value': "'classification'"},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'exposure_classification'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'classification'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '155']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '!='},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'exposure_classification'},{'id': '151', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'data_driven_classes'},{'id': '154', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '159', 'type': 'subscript', 'children': ['160', '166']},{'id': '160', 'type': 'subscript', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'exposure_classification'},{'id': '163', 'type': 'string', 'children': [], 'value': "'classes'"},{'id': '164', 'type': 'unary_operator', 'children': ['165'], 'value': '-'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'exposure_mapped'},{'id': '170', 'type': 'list', 'children': [], 'value': '[]'},{'id': '171', 'type': 'for_statement', 'children': ['172', '173', '181']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'exposure_mapped'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '-'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'unique_exposure'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'exposure_mapped'},{'id': '201', 'type': 'if_statement', 'children': ['202', '212', '222']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'in'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '222', 'type': 'else_clause', 'children': ['223']},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '237']},{'id': '232', 'type': 'subscript', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '236', 'type': 'string', 'children': [], 'value': "'value_map'"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'value_map'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '245']},{'id': '240', 'type': 'subscript', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '244', 'type': 'string', 'children': [], 'value': "'classification'"},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'classification'},{'id': '246', 'type': 'return_statement', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'layer'} | def _check_value_mapping(layer, exposure_key=None):
index = layer.fields().lookupField(exposure_type_field['field_name'])
unique_exposure = layer.uniqueValues(index)
if layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
if not exposure_key:
message = tr('Hazard value mapping missing exposure key.')
raise InvalidKeywordsForProcessingAlgorithm(message)
value_map = active_thresholds_value_maps(layer.keywords, exposure_key)
else:
value_map = layer.keywords.get('value_map')
if not value_map:
return layer
if layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
if not exposure_key:
message = tr('Hazard classification is missing exposure key.')
raise InvalidKeywordsForProcessingAlgorithm(message)
classification = active_classification(layer.keywords, exposure_key)
else:
classification = layer.keywords['classification']
exposure_classification = definition(classification)
other = None
if exposure_classification['key'] != data_driven_classes['key']:
other = exposure_classification['classes'][-1]['key']
exposure_mapped = []
for group in list(value_map.values()):
exposure_mapped.extend(group)
diff = list(unique_exposure - set(exposure_mapped))
if other in list(value_map.keys()):
value_map[other].extend(diff)
else:
value_map[other] = diff
layer.keywords['value_map'] = value_map
layer.keywords['classification'] = classification
return layer |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_inasafe_fields'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '5', 'type': 'block', 'children': ['6', '10', '86', '110', '124', '128', '180', '191', '195', '238', '244']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'if_statement', 'children': ['11', '20', '37', '64']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '17'], 'value': '=='},{'id': '12', 'type': 'subscript', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '16', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_exposure'},{'id': '19', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_fields'},{'id': '26', 'type': 'argument_list', 'children': ['27', '32']},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '31', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '32', 'type': 'subscript', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '36', 'type': 'string', 'children': [], 'value': "'exposure'"},{'id': '37', 'type': 'elif_clause', 'children': ['38', '47']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '44'], 'value': '=='},{'id': '39', 'type': 'subscript', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '43', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_hazard'},{'id': '46', 'type': 'string', 'children': [], 'value': "'key'"},{'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': 'fields'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_fields'},{'id': '53', 'type': 'argument_list', 'children': ['54', '59']},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '58', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '63', 'type': 'string', 'children': [], 'value': "'hazard'"},{'id': '64', 'type': 'elif_clause', 'children': ['65', '74']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '71'], 'value': '=='},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '70', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'layer_purpose_aggregation'},{'id': '73', 'type': 'string', 'children': [], 'value': "'key'"},{'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': 'fields'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_fields'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '85', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '86', 'type': 'try_statement', 'children': ['87', '106']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '98']},{'id': '89', 'type': 'subscript', 'children': ['90', '95']},{'id': '90', 'type': 'subscript', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '94', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'displaced_field'},{'id': '97', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'displaced_field'},{'id': '106', 'type': 'except_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'pass_statement', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'expected_fields'},{'id': '113', 'type': 'dictionary_comprehension', 'children': ['114', '121']},{'id': '114', 'type': 'pair', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '117', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '120', 'type': 'string', 'children': [], 'value': "'field_name'"},{'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_keywords'},{'id': '127', 'type': 'dictionary', 'children': []},{'id': '128', 'type': 'for_statement', 'children': ['129', '132', '147']},{'id': '129', 'type': 'pattern_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '146']},{'id': '136', 'type': 'attribute', 'children': ['137', '145']},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'if_statement', 'children': ['149', '152']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'in'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'expected_fields'},{'id': '152', 'type': 'block', 'children': ['153', '165', '172']},{'id': '153', 'type': 'if_statement', 'children': ['154', '159']},{'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': 'val'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'val'},{'id': '163', 'type': 'list', 'children': ['164'], 'value': '[val]'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sum_fields'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'val'},{'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': 'new_keywords'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'expected_fields'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '189']},{'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': 'layer'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '187', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'new_keywords'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'to_remove'},{'id': '194', 'type': 'list', 'children': [], 'value': '[]'},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '206']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '197', 'type': 'call', 'children': ['198', '205']},{'id': '198', 'type': 'attribute', 'children': ['199', '204']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'toList'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'if_statement', 'children': ['208', '226']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '214'], 'value': 'not'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '225']},{'id': '218', 'type': 'attribute', 'children': ['219', '224']},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '223', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'to_remove'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'remove_fields'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'to_remove'},{'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': 'LOGGER'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '%'},{'id': '251', 'type': 'string', 'children': [], 'value': "'Fields which have been removed from %s : %s'"},{'id': '252', 'type': 'tuple', 'children': ['253', '258']},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '257', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': "' '"},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'to_remove'} | def clean_inasafe_fields(layer):
fields = []
if layer.keywords['layer_purpose'] == layer_purpose_exposure['key']:
fields = get_fields(
layer.keywords['layer_purpose'], layer.keywords['exposure'])
elif layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
fields = get_fields(
layer.keywords['layer_purpose'], layer.keywords['hazard'])
elif layer.keywords['layer_purpose'] == layer_purpose_aggregation['key']:
fields = get_fields(
layer.keywords['layer_purpose'])
try:
if layer.keywords['inasafe_fields'][displaced_field['key']]:
fields.append(displaced_field)
except KeyError:
pass
expected_fields = {field['key']: field['field_name'] for field in fields}
new_keywords = {}
for key, val in list(layer.keywords.get('inasafe_fields').items()):
if key in expected_fields:
if isinstance(val, str):
val = [val]
sum_fields(layer, key, val)
new_keywords[key] = expected_fields[key]
layer.keywords['inasafe_fields'].update(new_keywords)
to_remove = []
for field in layer.fields().toList():
if field.name() not in list(layer.keywords['inasafe_fields'].values()):
to_remove.append(field.name())
remove_fields(layer, to_remove)
LOGGER.debug(
'Fields which have been removed from %s : %s'
% (layer.keywords['layer_purpose'], ' '.join(to_remove))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_size_is_needed'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '5', 'type': 'block', 'children': ['6', '17', '23', '33', '40', '53', '61', '71']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '9', 'type': 'call', 'children': ['10', '15']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'exposure'"},{'id': '17', 'type': 'if_statement', 'children': ['18', '20']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'indivisible_exposure_keys'},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '30']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'indivisible_exposure'},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'exposure'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'indivisible_exposure_keys'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'False', 'children': []},{'id': '40', 'type': 'if_statement', 'children': ['41', '50']},{'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': 'layer'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'geometryType'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'QgsWkbTypes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'PointGeometry'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'False', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '60', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'absolute_field_keys'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '67', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'count_fields'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74', '82']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'absolute_field_keys'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'True', 'children': []},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'False', 'children': []} | def _size_is_needed(layer):
exposure = layer.keywords.get('exposure')
if not exposure:
return False
indivisible_exposure_keys = [f['key'] for f in indivisible_exposure]
if exposure in indivisible_exposure_keys:
return False
if layer.geometryType() == QgsWkbTypes.PointGeometry:
return False
fields = layer.keywords['inasafe_fields']
absolute_field_keys = [f['key'] for f in count_fields]
for field in fields:
if field in absolute_field_keys:
return True
else:
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_remove_features'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '5', 'type': 'block', 'children': ['6', '14', '25', '33', '41', '52', '65']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '9', 'type': 'subscript', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '13', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'layer_subcategory'},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'compulsory_field'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_compulsory_fields'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'layer_subcategory'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'inasafe_fields'},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '40', 'type': 'string', 'children': [], 'value': "'inasafe_fields'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'inasafe_fields'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'compulsory_field'},{'id': '51', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '52', 'type': 'if_statement', 'children': ['53', '59']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '63', 'type': 'list', 'children': ['64'], 'value': '[field_names]'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '68', 'type': 'block', 'children': ['69', '88', '101', '107', '120', '126', '130', '291', '297']},{'id': '69', 'type': 'if_statement', 'children': ['70', '72']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '72', 'type': 'block', 'children': ['73', '83']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '%'},{'id': '77', 'type': 'string', 'children': [], 'value': "'Keyword %s is missing from %s'"},{'id': '78', 'type': 'tuple', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'compulsory_field'},{'id': '81', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'InvalidKeywordsForProcessingAlgorithm'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '91', 'type': 'call', 'children': ['92', '99']},{'id': '92', 'type': 'attribute', 'children': ['93', '98']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'lookupField'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'QgsFeatureRequest'},{'id': '106', 'type': 'argument_list', 'children': []},{'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': 'request'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'setSubsetOfAttributes'},{'id': '112', 'type': 'argument_list', 'children': ['113', '115']},{'id': '113', 'type': 'list', 'children': ['114'], 'value': '[field_name]'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'startEditing'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '138']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'getFeatures'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '138', 'type': 'block', 'children': ['139', '149', '231', '239', '259', '282']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'feat_attr'},{'id': '142', 'type': 'subscript', 'children': ['143', '148']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '149', 'type': 'if_statement', 'children': ['150', '167']},{'id': '150', 'type': '()', 'children': ['151']},{'id': '151', 'type': 'boolean_operator', 'children': ['152', '155'], 'value': 'or'},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'feat_attr'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '162'], 'value': 'and'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'feat_attr'},{'id': '161', 'type': 'string', 'children': [], 'value': "'isNull'"},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'feat_attr'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'isNull'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '172', '188', '213']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '=='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '171', 'type': 'string', 'children': [], 'value': "'hazard'"},{'id': '172', 'type': 'block', 'children': ['173', '184']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'deleteFeature'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'augmented_assignment', 'children': ['186', '187'], 'value': '+='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'elif_clause', 'children': ['189', '192']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '=='},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '191', 'type': 'string', 'children': [], 'value': "'aggregation'"},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'changeAttributeValue'},{'id': '198', 'type': 'argument_list', 'children': ['199', '204', '205']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'elif_clause', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'layer_purpose'},{'id': '216', 'type': 'string', 'children': [], 'value': "'exposure'"},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'changeAttributeValue'},{'id': '223', 'type': 'argument_list', 'children': ['224', '229', '230']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '230', 'type': 'string', 'children': [], 'value': "''"},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'if_statement', 'children': ['240', '242']},{'id': '240', 'type': 'not_operator', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '242', 'type': 'block', 'children': ['243', '254', '258']},{'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': 'layer'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'deleteFeature'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '253', 'type': 'argument_list', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'augmented_assignment', 'children': ['256', '257'], 'value': '+='},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '257', 'type': 'integer', 'children': [], 'value': '1'},{'id': '258', 'type': 'continue_statement', 'children': []},{'id': '259', 'type': 'if_statement', 'children': ['260', '265']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'isEmpty'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'block', 'children': ['266', '277', '281']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'deleteFeature'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '276', 'type': 'argument_list', 'children': []},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'augmented_assignment', 'children': ['279', '280'], 'value': '+='},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'continue_statement', 'children': []},{'id': '282', 'type': 'if_statement', 'children': ['283', '289']},{'id': '283', 'type': 'not_operator', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'isGeosValid'},{'id': '288', 'type': 'argument_list', 'children': []},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'pass_statement', 'children': []},{'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': 'layer'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'commitChanges'},{'id': '296', 'type': 'argument_list', 'children': []},{'id': '297', 'type': 'if_statement', 'children': ['298', '299', '315']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'critical'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'binary_operator', 'children': ['307', '308'], 'value': '%'},{'id': '307', 'type': 'string', 'children': [], 'value': "'Features which have been removed from %s : %s'"},{'id': '308', 'type': 'tuple', 'children': ['309', '314']},{'id': '309', 'type': 'subscript', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '313', 'type': 'string', 'children': [], 'value': "'layer_purpose'"},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '315', 'type': 'else_clause', 'children': ['316']},{'id': '316', 'type': 'block', 'children': ['317']},{'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': 'LOGGER'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'binary_operator', 'children': ['324', '327'], 'value': '%'},{'id': '324', 'type': 'concatenated_string', 'children': ['325', '326']},{'id': '325', 'type': 'string', 'children': [], 'value': "'No feature has been removed from %s during the vector layer '"},{'id': '326', 'type': 'string', 'children': [], 'value': "'preparation'"},{'id': '327', 'type': 'subscript', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'layer'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '331', 'type': 'string', 'children': [], 'value': "'layer_purpose'"} | def _remove_features(layer):
layer_purpose = layer.keywords['layer_purpose']
layer_subcategory = layer.keywords.get(layer_purpose)
compulsory_field = get_compulsory_fields(layer_purpose, layer_subcategory)
inasafe_fields = layer.keywords['inasafe_fields']
field_names = inasafe_fields.get(compulsory_field['key'])
if not isinstance(field_names, list):
field_names = [field_names]
for field_name in field_names:
if not field_name:
message = 'Keyword %s is missing from %s' % (
compulsory_field['key'], layer_purpose)
raise InvalidKeywordsForProcessingAlgorithm(message)
index = layer.fields().lookupField(field_name)
request = QgsFeatureRequest()
request.setSubsetOfAttributes([field_name], layer.fields())
layer.startEditing()
i = 0
for feature in layer.getFeatures(request):
feat_attr = feature.attributes()[index]
if (feat_attr is None
or (hasattr(feat_attr, 'isNull')
and feat_attr.isNull())):
if layer_purpose == 'hazard':
layer.deleteFeature(feature.id())
i += 1
elif layer_purpose == 'aggregation':
layer.changeAttributeValue(
feature.id(), index, str(feature.id()))
elif layer_purpose == 'exposure':
layer.changeAttributeValue(
feature.id(), index, '')
geometry = feature.geometry()
if not geometry:
layer.deleteFeature(feature.id())
i += 1
continue
if geometry.isEmpty():
layer.deleteFeature(feature.id())
i += 1
continue
if not geometry.isGeosValid():
pass
layer.commitChanges()
if i:
LOGGER.critical(
'Features which have been removed from %s : %s'
% (layer.keywords['layer_purpose'], i))
else:
LOGGER.info(
'No feature has been removed from %s during the vector layer '
'preparation' % layer.keywords['layer_purpose']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_profiles'},{'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': 'overwrite'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '69']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'sort_by_locale'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unsorted_profiles'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '14', 'type': 'block', 'children': ['15', '22', '32', '36', '40', '65']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'unsorted_profiles'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': "'_%s'"},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '29', 'type': 'slice', 'children': ['30', '31']},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'integer', 'children': [], 'value': '2'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'profiles_our_locale'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'profiles_remaining'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'profile_name'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unsorted_profiles'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '56']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'profile_name'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'profiles_our_locale'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'profile_name'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'profiles_remaining'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'profile_name'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'profiles_our_locale'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'profiles_remaining'},{'id': '69', 'type': 'if_statement', 'children': ['70', '74', '81']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'root_directory'},{'id': '74', 'type': 'block', 'children': ['75', '79']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'profiles'},{'id': '78', 'type': 'list', 'children': [], 'value': '[]'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'profiles'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83', '97', '104', '122', '174', '181', '208', '218']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'root_directory'},{'id': '96', 'type': 'string', 'children': [], 'value': "'minimum_needs'"},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'path_name'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'resources_path'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': "'minimum_needs'"},{'id': '104', 'type': 'if_statement', 'children': ['105', '114']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'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': 'os'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '130']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'path_name'},{'id': '130', 'type': 'block', 'children': ['131', '143', '155']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'path_name'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'destination_file'},{'id': '146', 'type': 'call', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'file_name'},{'id': '155', 'type': 'if_statement', 'children': ['156', '167']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '166'], 'value': 'or'},{'id': '157', 'type': 'not_operator', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'destination_file'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'source_file'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'destination_file'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'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': 'move_old_profile'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'profiles'},{'id': '184', 'type': 'list_comprehension', 'children': ['185', '191', '199']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '187', 'type': 'slice', 'children': ['188', '189']},{'id': '188', 'type': 'colon', 'children': []},{'id': '189', 'type': 'unary_operator', 'children': ['190'], 'value': '-'},{'id': '190', 'type': 'integer', 'children': [], 'value': '5'},{'id': '191', 'type': 'for_in_clause', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'locale_minimum_needs_dir'},{'id': '199', 'type': 'if_clause', 'children': ['200']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '207'], 'value': '=='},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '203', 'type': 'slice', 'children': ['204', '206']},{'id': '204', 'type': 'unary_operator', 'children': ['205'], 'value': '-'},{'id': '205', 'type': 'integer', 'children': [], 'value': '5'},{'id': '206', 'type': 'colon', 'children': []},{'id': '207', 'type': 'string', 'children': [], 'value': "'.json'"},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'profiles'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'sort_by_locale'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'profiles'},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'profiles'} | def get_profiles(self, overwrite=False):
def sort_by_locale(unsorted_profiles, locale):
if locale is None:
return unsorted_profiles
locale = '_%s' % locale[:2]
profiles_our_locale = []
profiles_remaining = []
for profile_name in unsorted_profiles:
if locale in profile_name:
profiles_our_locale.append(profile_name)
else:
profiles_remaining.append(profile_name)
return profiles_our_locale + profiles_remaining
if not self.root_directory:
profiles = []
return profiles
else:
locale_minimum_needs_dir = os.path.join(
self.root_directory, 'minimum_needs')
path_name = resources_path('minimum_needs')
if not os.path.exists(locale_minimum_needs_dir):
os.makedirs(locale_minimum_needs_dir)
for file_name in os.listdir(path_name):
source_file = os.path.join(path_name, file_name)
destination_file = os.path.join(
locale_minimum_needs_dir, file_name)
if not os.path.exists(destination_file) or overwrite:
copy(source_file, destination_file)
self.move_old_profile(locale_minimum_needs_dir)
profiles = [
profile[:-5] for profile in
os.listdir(locale_minimum_needs_dir) if
profile[-5:] == '.json']
profiles = sort_by_locale(profiles, self.locale)
return profiles |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_keywords_by_order'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '6', 'type': 'block', 'children': ['7', '29', '35', '62', '82']},{'id': '7', 'type': 'for_statement', 'children': ['8', '11', '19']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'delete_statement', 'children': ['26']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ordered_keywords'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '50']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'in'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'identifier', 'children': [], 'value': 'keywords'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ordered_keywords'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'not'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ordered_keywords'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ordered_keywords'} | def sorted_keywords_by_order(keywords, order):
for key, value in list(keywords.items()):
if value is None:
del keywords[key]
ordered_keywords = OrderedDict()
for key in order:
if key in list(keywords.keys()):
ordered_keywords[key] = keywords.get(key)
for keyword in keywords:
if keyword not in order:
ordered_keywords[keyword] = keywords.get(keyword)
return ordered_keywords |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_layer_modes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'subcategory'},{'id': '5', 'type': 'block', 'children': ['6', '15']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'layer_modes'},{'id': '9', 'type': 'subscript', 'children': ['10', '14']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'subcategory'},{'id': '14', 'type': 'string', 'children': [], 'value': "'layer_modes'"},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'layer_modes'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'lambda', 'children': ['23', '25']},{'id': '23', 'type': 'lambda_parameters', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '27', 'type': 'string', 'children': [], 'value': "'key'"} | def get_layer_modes(subcategory):
layer_modes = definition(subcategory)['layer_modes']
return sorted(layer_modes, key=lambda k: k['key']) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_ordered_combo_item'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'count_selected_features'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '39', '47', '106']},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'count_selected_features'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'augmented_assignment', 'children': ['23', '24'], 'value': '+='},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '38'], 'value': '+'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '+'},{'id': '26', 'type': 'string', 'children': [], 'value': "' ('"},{'id': '27', 'type': 'call', 'children': ['28', '34']},{'id': '28', 'type': 'attribute', 'children': ['29', '33']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tr'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'{count} selected features'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'count_selected_features'},{'id': '38', 'type': 'string', 'children': [], 'value': "')'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '54']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'combo_index'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '54', 'type': 'block', 'children': ['55', '64']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'item_text'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'itemText'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'combo_index'},{'id': '64', 'type': 'if_statement', 'children': ['65', '80']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '79'], 'value': '<'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '68', 'type': 'argument_list', 'children': ['69', '74']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'item_text'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81', '105']},{'id': '81', 'type': 'if_statement', 'children': ['82', '83', '94']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'icon'},{'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': 'combo'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'insertItem'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92', '93']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'combo_index'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'else_clause', 'children': ['95']},{'id': '95', 'type': 'block', 'children': ['96']},{'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': 'combo'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'insertItem'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'combo_index'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '105', 'type': 'return_statement', 'children': []},{'id': '106', 'type': 'if_statement', 'children': ['107', '108', '119']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'insertItem'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117', '118']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'icon'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'combo'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'insertItem'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'data'} | def add_ordered_combo_item(
combo, text, data=None, count_selected_features=None, icon=None):
if count_selected_features is not None:
text += ' (' + tr('{count} selected features').format(
count=count_selected_features) + ')'
size = combo.count()
for combo_index in range(0, size):
item_text = combo.itemText(combo_index)
if cmp(text.lower(), item_text.lower()) < 0:
if icon:
combo.insertItem(combo_index, icon, text, data)
else:
combo.insertItem(combo_index, text, data)
return
if icon:
combo.insertItem(size, icon, text, data)
else:
combo.insertItem(size, text, data) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'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', '15']},{'id': '8', 'type': 'attribute', 'children': ['9', '14']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'JSSObjectList'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'lambda', 'children': ['19', '21']},{'id': '19', 'type': 'lambda_parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'id'} | def sort(self):
super(JSSObjectList, self).sort(key=lambda k: k.id) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_name'},{'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', '15']},{'id': '8', 'type': 'attribute', 'children': ['9', '14']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'JSSObjectList'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'lambda', 'children': ['19', '21']},{'id': '19', 'type': 'lambda_parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'} | def sort_by_name(self):
super(JSSObjectList, self).sort(key=lambda k: k.name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_sorted_task_dependencies'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'task_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '7', 'type': 'block', 'children': ['8', '21', '54', '83', '91', '98', '110', '114', '123', '131', '143']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"find_sorted_task_dependencies {} {}"'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'task_name'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cot_input_dependencies'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '31']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_craft_dependency_tuple'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'task_name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'task_type'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '35']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'task_type'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '35', 'type': 'call', 'children': ['36', '53']},{'id': '36', 'type': 'attribute', 'children': ['37', '52']},{'id': '37', 'type': 'call', 'children': ['38', '49']},{'id': '38', 'type': 'attribute', 'children': ['39', '48']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '43', 'type': 'string', 'children': [], 'value': "'extra'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'chainOfTrust'"},{'id': '47', 'type': 'dictionary', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'inputs'"},{'id': '51', 'type': 'dictionary', 'children': []},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts_dependencies'},{'id': '57', 'type': 'list_comprehension', 'children': ['58', '68']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_craft_dependency_tuple'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '65']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'task_name'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'artifact_dict'},{'id': '64', 'type': 'string', 'children': [], 'value': "'taskType'"},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'artifact_dict'},{'id': '67', 'type': 'string', 'children': [], 'value': "'taskId'"},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'artifact_dict'},{'id': '70', 'type': 'call', 'children': ['71', '80']},{'id': '71', 'type': 'attribute', 'children': ['72', '79']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'payload'"},{'id': '78', 'type': 'dictionary', 'children': []},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'upstreamArtifacts'"},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '86', 'type': 'list', 'children': ['87', '89'], 'value': '[*cot_input_dependencies, *upstream_artifacts_dependencies]'},{'id': '87', 'type': 'list_splat', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cot_input_dependencies'},{'id': '89', 'type': 'list_splat', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts_dependencies'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_sort_dependencies_by_name_then_task_id'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'parent_task_id'},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '106'], 'value': 'or'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_parent_task_id'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'get_decision_task_id'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'parent_task_type'},{'id': '113', 'type': 'string', 'children': [], 'value': "'parent'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'parent_tuple'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_craft_dependency_tuple'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'task_name'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'parent_task_type'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'parent_task_id'},{'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': 'dependencies'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parent_tuple'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': "'found dependencies: {}'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dependencies'} | def find_sorted_task_dependencies(task, task_name, task_id):
log.info("find_sorted_task_dependencies {} {}".format(task_name, task_id))
cot_input_dependencies = [
_craft_dependency_tuple(task_name, task_type, task_id)
for task_type, task_id in task['extra'].get('chainOfTrust', {}).get('inputs', {}).items()
]
upstream_artifacts_dependencies = [
_craft_dependency_tuple(task_name, artifact_dict['taskType'], artifact_dict['taskId'])
for artifact_dict in task.get('payload', {}).get('upstreamArtifacts', [])
]
dependencies = [*cot_input_dependencies, *upstream_artifacts_dependencies]
dependencies = _sort_dependencies_by_name_then_task_id(dependencies)
parent_task_id = get_parent_task_id(task) or get_decision_task_id(task)
parent_task_type = 'parent'
parent_tuple = _craft_dependency_tuple(task_name, parent_task_type, parent_task_id)
dependencies.insert(0, parent_tuple)
log.info('found dependencies: {}'.format(dependencies))
return dependencies |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all_artifacts_per_task_id'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'id': '6', 'type': 'block', 'children': ['7', '11', '76', '100', '122']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '16', 'type': 'block', 'children': ['17', '39']},{'id': '17', 'type': 'if_statement', 'children': ['18', '23']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': 'in'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'task_type'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'PARENT_TASK_TYPES'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'add_enumerable_item_to_dict'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31', '36']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '38', 'type': 'string', 'children': [], 'value': "'public/task-graph.json'"},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'in'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'task_type'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'DECISION_TASK_TYPES'},{'id': '45', 'type': 'block', 'children': ['46', '61']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'add_enumerable_item_to_dict'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53', '58']},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '60', 'type': 'string', 'children': [], 'value': "'public/actions.json'"},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'add_enumerable_item_to_dict'},{'id': '64', 'type': 'argument_list', 'children': ['65', '68', '73']},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'link'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '75', 'type': 'string', 'children': [], 'value': "'public/parameters.yml'"},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'upstream_dict'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'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': 'add_enumerable_item_to_dict'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90', '95']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'upstream_dict'},{'id': '94', 'type': 'string', 'children': [], 'value': "'taskId'"},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'upstream_dict'},{'id': '99', 'type': 'string', 'children': [], 'value': "'paths'"},{'id': '100', 'type': 'for_statement', 'children': ['101', '104', '109']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'all_artifacts_per_task_id'} | def get_all_artifacts_per_task_id(chain, upstream_artifacts):
all_artifacts_per_task_id = {}
for link in chain.links:
if link.task_type in PARENT_TASK_TYPES:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/task-graph.json'
)
if link.task_type in DECISION_TASK_TYPES:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/actions.json'
)
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=link.task_id, item='public/parameters.yml'
)
if upstream_artifacts:
for upstream_dict in upstream_artifacts:
add_enumerable_item_to_dict(
dict_=all_artifacts_per_task_id, key=upstream_dict['taskId'], item=upstream_dict['paths']
)
for task_id, paths in all_artifacts_per_task_id.items():
all_artifacts_per_task_id[task_id] = sorted(set(paths))
return all_artifacts_per_task_id |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_upstream_artifacts_full_paths_per_task_id'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '5', 'type': 'block', 'children': ['6', '16', '30', '37', '41', '45', '122']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'id': '9', 'type': 'subscript', 'children': ['10', '15']},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '14', 'type': 'string', 'children': [], 'value': "'payload'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'upstreamArtifacts'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'task_ids_and_relative_paths'},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '27']},{'id': '20', 'type': 'tuple', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'artifact_definition'},{'id': '23', 'type': 'string', 'children': [], 'value': "'taskId'"},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'artifact_definition'},{'id': '26', 'type': 'string', 'children': [], 'value': "'paths'"},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'artifact_definition'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'optional_artifacts_per_task_id'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_optional_artifacts_per_task_id'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts_full_paths_per_task_id'},{'id': '40', 'type': 'dictionary', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'failed_paths_per_task_id'},{'id': '44', 'type': 'dictionary', 'children': []},{'id': '45', 'type': 'for_statement', 'children': ['46', '49', '50']},{'id': '46', 'type': 'pattern_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'task_ids_and_relative_paths'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'try_statement', 'children': ['56', '79']},{'id': '56', 'type': 'block', 'children': ['57', '66']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'path_to_add'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_and_check_single_upstream_artifact_full_path'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'add_enumerable_item_to_dict'},{'id': '69', 'type': 'argument_list', 'children': ['70', '73', '76']},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts_full_paths_per_task_id'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'path_to_add'},{'id': '79', 'type': 'except_clause', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ScriptWorkerTaskException'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '92', '119']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'optional_artifacts_per_task_id'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'block', 'children': ['93', '106']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': '\'Optional artifact "{}" of task "{}" not found\''},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'add_enumerable_item_to_dict'},{'id': '109', 'type': 'argument_list', 'children': ['110', '113', '116']},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dict_'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'failed_paths_per_task_id'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'task_id'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': []},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'expression_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'upstream_artifacts_full_paths_per_task_id'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'failed_paths_per_task_id'} | def get_upstream_artifacts_full_paths_per_task_id(context):
upstream_artifacts = context.task['payload']['upstreamArtifacts']
task_ids_and_relative_paths = [
(artifact_definition['taskId'], artifact_definition['paths'])
for artifact_definition in upstream_artifacts
]
optional_artifacts_per_task_id = get_optional_artifacts_per_task_id(upstream_artifacts)
upstream_artifacts_full_paths_per_task_id = {}
failed_paths_per_task_id = {}
for task_id, paths in task_ids_and_relative_paths:
for path in paths:
try:
path_to_add = get_and_check_single_upstream_artifact_full_path(context, task_id, path)
add_enumerable_item_to_dict(
dict_=upstream_artifacts_full_paths_per_task_id,
key=task_id, item=path_to_add
)
except ScriptWorkerTaskException:
if path in optional_artifacts_per_task_id.get(task_id, []):
log.warning('Optional artifact "{}" of task "{}" not found'.format(path, task_id))
add_enumerable_item_to_dict(
dict_=failed_paths_per_task_id,
key=task_id, item=path
)
else:
raise
return upstream_artifacts_full_paths_per_task_id, failed_paths_per_task_id |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_PreparedData'},{'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': 'order_by'},{'id': '7', 'type': 'tuple', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '26', '66', '175']},{'id': '9', 'type': 'if_statement', 'children': ['10', '12']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '20', 'type': 'subscript', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '24', 'type': 'slice', 'children': ['25']},{'id': '25', 'type': 'colon', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '60']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '35'], 'value': 'or'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '49'], 'value': 'and'},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '43'], 'value': 'and'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '=='},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '48', 'type': 'integer', 'children': [], 'value': '2'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '57'], 'value': 'in'},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'list', 'children': ['58', '59'], 'value': '["asc", "desc"]'},{'id': '58', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '59', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '64', 'type': 'tuple', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '72']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'if_statement', 'children': ['74', '81', '101', '166']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'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': 'sorted_data'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'lambda', 'children': ['91', '93']},{'id': '91', 'type': 'lambda_parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'call', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'elif_clause', 'children': ['102', '129']},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '118'], 'value': 'and'},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '112'], 'value': 'and'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'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': 'key'},{'id': '117', 'type': 'integer', 'children': [], 'value': '2'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '126'], 'value': 'in'},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'tuple', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '128', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '129', 'type': 'block', 'children': ['130', '146']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '133', 'type': 'lambda', 'children': ['134', '136']},{'id': '134', 'type': 'lambda_parameters', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'call', 'children': ['137', '142']},{'id': '137', 'type': 'attribute', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '165'], 'value': '!='},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'DataTableException'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'concatenated_string', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': '"Expected tuple with second value: "'},{'id': '174', 'type': 'string', 'children': [], 'value': '"\'asc\' or \'desc\'"'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sorted_data'} | def _PreparedData(self, order_by=()):
if not order_by:
return self.__data
sorted_data = self.__data[:]
if isinstance(order_by, six.string_types) or (
isinstance(order_by, tuple) and len(order_by) == 2 and
order_by[1].lower() in ["asc", "desc"]):
order_by = (order_by,)
for key in reversed(order_by):
if isinstance(key, six.string_types):
sorted_data.sort(key=lambda x: x[0].get(key))
elif (isinstance(key, (list, tuple)) and len(key) == 2 and
key[1].lower() in ("asc", "desc")):
key_func = lambda x: x[0].get(key[0])
sorted_data.sort(key=key_func, reverse=key[1].lower() != "asc")
else:
raise DataTableException("Expected tuple with second value: "
"'asc' or 'desc'")
return sorted_data |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ToJSCode'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '11', 'type': 'tuple', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '19', '36', '53', '59', '79', '150', '163', '314']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'DataTableJSONEncoder'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '27', 'type': 'list_comprehension', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '30', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'list_comprehension', 'children': ['43', '48']},{'id': '43', 'type': 'tuple', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '46', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'},{'id': '57', 'type': 'string', 'children': [], 'value': '"var %s = new google.visualization.DataTable();\\n"'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'custom_properties'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'augmented_assignment', 'children': ['66', '67'], 'value': '+='},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '%'},{'id': '68', 'type': 'string', 'children': [], 'value': '"%s.setTableProperties(%s);\\n"'},{'id': '69', 'type': 'tuple', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'custom_properties'},{'id': '79', 'type': 'for_statement', 'children': ['80', '83', '87']},{'id': '80', 'type': 'pattern_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '87', 'type': 'block', 'children': ['88', '125']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '%'},{'id': '92', 'type': 'string', 'children': [], 'value': '"%s.addColumn(%s, %s, %s);\\n"'},{'id': '93', 'type': 'tuple', 'children': ['94', '95', '105', '115']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '104', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '114', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '124', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '125', 'type': 'if_statement', 'children': ['126', '131']},{'id': '126', 'type': 'subscript', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '130', 'type': 'string', 'children': [], 'value': '"custom_properties"'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'augmented_assignment', 'children': ['134', '135'], 'value': '+='},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '%'},{'id': '136', 'type': 'string', 'children': [], 'value': '"%s.setColumnProperties(%d, %s);\\n"'},{'id': '137', 'type': 'tuple', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'encode'},{'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': 'col_dict'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '149', 'type': 'string', 'children': [], 'value': '"custom_properties"'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '153'], 'value': '+='},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'},{'id': '154', 'type': 'string', 'children': [], 'value': '"%s.addRows(%d);\\n"'},{'id': '155', 'type': 'tuple', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '163', 'type': 'for_statement', 'children': ['164', '169', '178']},{'id': '164', 'type': 'tuple_pattern', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '166', 'type': 'tuple_pattern', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_PreparedData'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '178', 'type': 'block', 'children': ['179', '297']},{'id': '179', 'type': 'for_statement', 'children': ['180', '183', '187']},{'id': '180', 'type': 'tuple_pattern', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '187', 'type': 'block', 'children': ['188', '200', '216']},{'id': '188', 'type': 'if_statement', 'children': ['189', '198']},{'id': '189', 'type': 'boolean_operator', 'children': ['190', '193'], 'value': 'or'},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'not'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '197'], 'value': 'is'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '197', 'type': 'None', 'children': []},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'continue_statement', 'children': []},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'CoerceValue'},{'id': '207', 'type': 'argument_list', 'children': ['208', '211']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '211', 'type': 'subscript', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '215', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '216', 'type': 'if_statement', 'children': ['217', '222', '279']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '222', 'type': 'block', 'children': ['223', '227', '250']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'cell_cp'},{'id': '226', 'type': 'string', 'children': [], 'value': '""'},{'id': '227', 'type': 'if_statement', 'children': ['228', '234']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '233'], 'value': '=='},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '233', 'type': 'integer', 'children': [], 'value': '3'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'cell_cp'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '%'},{'id': '239', 'type': 'string', 'children': [], 'value': '", %s"'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '249', 'type': 'integer', 'children': [], 'value': '2'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'augmented_assignment', 'children': ['252', '253'], 'value': '+='},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '253', 'type': '()', 'children': ['254']},{'id': '254', 'type': 'binary_operator', 'children': ['255', '256'], 'value': '%'},{'id': '255', 'type': 'string', 'children': [], 'value': '"%s.setCell(%d, %d, %s, %s%s);\\n"'},{'id': '256', 'type': 'tuple', 'children': ['257', '258', '259', '260', '269', '278']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'EscapeForJSCode'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'EscapeForJSCode'},{'id': '273', 'type': 'argument_list', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '277', 'type': 'integer', 'children': [], 'value': '1'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'cell_cp'},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'augmented_assignment', 'children': ['283', '284'], 'value': '+='},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '%'},{'id': '285', 'type': 'string', 'children': [], 'value': '"%s.setCell(%d, %d, %s);\\n"'},{'id': '286', 'type': 'tuple', 'children': ['287', '288', '289', '290']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'EscapeForJSCode'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '297', 'type': 'if_statement', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '299', 'type': 'block', 'children': ['300']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'augmented_assignment', 'children': ['302', '303'], 'value': '+='},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'jscode'},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': '"%s.setRowProperties(%d, %s);\\n"'},{'id': '305', 'type': 'tuple', 'children': ['306', '307', '308']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'encoder'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '314', 'type': 'return_statement', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'jscode'} | def ToJSCode(self, name, columns_order=None, order_by=()):
encoder = DataTableJSONEncoder()
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
jscode = "var %s = new google.visualization.DataTable();\n" % name
if self.custom_properties:
jscode += "%s.setTableProperties(%s);\n" % (
name, encoder.encode(self.custom_properties))
for i, col in enumerate(columns_order):
jscode += "%s.addColumn(%s, %s, %s);\n" % (
name,
encoder.encode(col_dict[col]["type"]),
encoder.encode(col_dict[col]["label"]),
encoder.encode(col_dict[col]["id"]))
if col_dict[col]["custom_properties"]:
jscode += "%s.setColumnProperties(%d, %s);\n" % (
name, i, encoder.encode(col_dict[col]["custom_properties"]))
jscode += "%s.addRows(%d);\n" % (name, len(self.__data))
for (i, (row, cp)) in enumerate(self._PreparedData(order_by)):
for (j, col) in enumerate(columns_order):
if col not in row or row[col] is None:
continue
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
cell_cp = ""
if len(value) == 3:
cell_cp = ", %s" % encoder.encode(row[col][2])
jscode += ("%s.setCell(%d, %d, %s, %s%s);\n" %
(name, i, j,
self.EscapeForJSCode(encoder, value[0]),
self.EscapeForJSCode(encoder, value[1]), cell_cp))
else:
jscode += "%s.setCell(%d, %d, %s);\n" % (
name, i, j, self.EscapeForJSCode(encoder, value))
if cp:
jscode += "%s.setRowProperties(%d, %s);\n" % (
name, i, encoder.encode(cp))
return jscode |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ToHtml'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '10', 'type': 'tuple', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '20', '24', '28', '32', '36', '53', '70', '74', '96', '107', '111', '224', '235']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'table_template'},{'id': '15', 'type': 'string', 'children': [], 'value': '"<html><body><table border=\\"1\\">%s</table></body></html>"'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'columns_template'},{'id': '19', 'type': 'string', 'children': [], 'value': '"<thead><tr>%s</tr></thead>"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'rows_template'},{'id': '23', 'type': 'string', 'children': [], 'value': '"<tbody>%s</tbody>"'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'row_template'},{'id': '27', 'type': 'string', 'children': [], 'value': '"<tr>%s</tr>"'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'header_cell_template'},{'id': '31', 'type': 'string', 'children': [], 'value': '"<th>%s</th>"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cell_template'},{'id': '35', 'type': 'string', 'children': [], 'value': '"<td>%s</td>"'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '47', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '65']},{'id': '60', 'type': 'tuple', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '63', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '73', 'type': 'list', 'children': [], 'value': '[]'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'header_cell_template'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '95', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'columns_html'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'columns_template'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': '""'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'columns_list'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rows_list'},{'id': '110', 'type': 'list', 'children': [], 'value': '[]'},{'id': '111', 'type': 'for_statement', 'children': ['112', '115', '121']},{'id': '112', 'type': 'pattern_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'unused_cp'},{'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': '_PreparedData'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '121', 'type': 'block', 'children': ['122', '126', '210']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '129', 'type': 'block', 'children': ['130', '134', '161']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '133', 'type': 'string', 'children': [], 'value': '""'},{'id': '134', 'type': 'if_statement', 'children': ['135', '144']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '139'], 'value': 'and'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'in'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': 'is'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'CoerceValue'},{'id': '152', 'type': 'argument_list', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '160', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '161', 'type': 'if_statement', 'children': ['162', '167', '189']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '%'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'cell_template'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ToString'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'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': 'cells_list'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'cell_template'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'html'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ToString'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'rows_list'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '%'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'row_template'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': '""'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'rows_html'},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'rows_template'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': '""'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'rows_list'},{'id': '235', 'type': 'return_statement', 'children': ['236']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '%'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'table_template'},{'id': '238', 'type': '()', 'children': ['239']},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'columns_html'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'rows_html'} | def ToHtml(self, columns_order=None, order_by=()):
table_template = "<html><body><table border=\"1\">%s</table></body></html>"
columns_template = "<thead><tr>%s</tr></thead>"
rows_template = "<tbody>%s</tbody>"
row_template = "<tr>%s</tr>"
header_cell_template = "<th>%s</th>"
cell_template = "<td>%s</td>"
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
columns_list = []
for col in columns_order:
columns_list.append(header_cell_template %
html.escape(col_dict[col]["label"]))
columns_html = columns_template % "".join(columns_list)
rows_list = []
for row, unused_cp in self._PreparedData(order_by):
cells_list = []
for col in columns_order:
value = ""
if col in row and row[col] is not None:
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
cells_list.append(cell_template % html.escape(self.ToString(value[1])))
else:
cells_list.append(cell_template % html.escape(self.ToString(value)))
rows_list.append(row_template % "".join(cells_list))
rows_html = rows_template % "".join(rows_list)
return table_template % (columns_html + rows_html) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ToCsv'},{'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': 'columns_order'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '10', 'type': 'tuple', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '13', 'type': 'string', 'children': [], 'value': '","'},{'id': '14', 'type': 'block', 'children': ['15', '23', '35', '52', '69', '92', '110', '239']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'csv_buffer'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'csv_buffer'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'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': 'columns_order'},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '46', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '64']},{'id': '59', 'type': 'tuple', 'children': ['60', '63']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '62', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '69', 'type': 'function_definition', 'children': ['70', '71', '73']},{'id': '70', 'type': 'function_name', 'children': [], 'value': 'ensure_str'},{'id': '71', 'type': 'parameters', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '73', 'type': 'block', 'children': ['74', '76', '85']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': '"Compatibility function. Ensures using of str rather than unicode."'},{'id': '76', 'type': 'if_statement', 'children': ['77', '82']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'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': 'writer'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'list_comprehension', 'children': ['99', '107']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ensure_str'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '106', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '110', 'type': 'for_statement', 'children': ['111', '114', '120']},{'id': '111', 'type': 'pattern_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'unused_cp'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_PreparedData'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '120', 'type': 'block', 'children': ['121', '125', '232']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '124', 'type': 'list', 'children': [], 'value': '[]'},{'id': '125', 'type': 'for_statement', 'children': ['126', '127', '128']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '128', 'type': 'block', 'children': ['129', '133', '160']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '132', 'type': 'string', 'children': [], 'value': '""'},{'id': '133', 'type': 'if_statement', 'children': ['134', '143']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '138'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'in'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': 'is'},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '142', 'type': 'None', 'children': []},{'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': 'value'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'CoerceValue'},{'id': '151', 'type': 'argument_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '159', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '160', 'type': 'if_statement', 'children': ['161', '166', '215']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'if_statement', 'children': ['168', '178', '196']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '174'], 'value': 'in'},{'id': '169', 'type': 'subscript', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '173', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '174', 'type': 'list', 'children': ['175', '176', '177'], 'value': '["date", "datetime", "timeofday"]'},{'id': '175', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '176', 'type': 'string', 'children': [], 'value': '"datetime"'},{'id': '177', 'type': 'string', 'children': [], 'value': '"timeofday"'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'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': 'ensure_str'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ToString'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ensure_str'},{'id': '206', 'type': 'argument_list', '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': 'ToString'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'else_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217']},{'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': 'cells_list'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ensure_str'},{'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': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ToString'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cells_list'},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'csv_buffer'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '244', 'type': 'argument_list', 'children': []} | def ToCsv(self, columns_order=None, order_by=(), separator=","):
csv_buffer = six.StringIO()
writer = csv.writer(csv_buffer, delimiter=separator)
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
def ensure_str(s):
"Compatibility function. Ensures using of str rather than unicode."
if isinstance(s, str):
return s
return s.encode("utf-8")
writer.writerow([ensure_str(col_dict[col]["label"])
for col in columns_order])
for row, unused_cp in self._PreparedData(order_by):
cells_list = []
for col in columns_order:
value = ""
if col in row and row[col] is not None:
value = self.CoerceValue(row[col], col_dict[col]["type"])
if isinstance(value, tuple):
if col_dict[col]["type"] in ["date", "datetime", "timeofday"]:
cells_list.append(ensure_str(self.ToString(value[1])))
else:
cells_list.append(ensure_str(self.ToString(value[0])))
else:
cells_list.append(ensure_str(self.ToString(value)))
writer.writerow(cells_list)
return csv_buffer.getvalue() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ToJSonObj'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '10', 'type': 'tuple', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '29', '46', '50', '103', '107', '248', '258', '271']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '20', 'type': 'list_comprehension', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '23', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '41']},{'id': '36', 'type': 'tuple', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '39', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '__columns'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'col_objs'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '53', 'type': 'block', 'children': ['54', '79', '96']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'col_obj'},{'id': '57', 'type': 'dictionary', 'children': ['58', '65', '72']},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '64', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '71', 'type': 'string', 'children': [], 'value': '"label"'},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '74', 'type': 'subscript', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '78', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '79', 'type': 'if_statement', 'children': ['80', '85']},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '84', 'type': 'string', 'children': [], 'value': '"custom_properties"'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'col_obj'},{'id': '90', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'col_id'},{'id': '95', 'type': 'string', 'children': [], 'value': '"custom_properties"'},{'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': 'col_objs'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'col_obj'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'row_objs'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'for_statement', 'children': ['108', '111', '117']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '_PreparedData'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '117', 'type': 'block', 'children': ['118', '122', '225', '232', '241']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cell_objs'},{'id': '121', 'type': 'list', 'children': [], 'value': '[]'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '125', 'type': 'block', 'children': ['126', '146', '218']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'CoerceValue'},{'id': '133', 'type': 'argument_list', 'children': ['134', '141']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'col_dict'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '145', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150', '155', '209']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': 'elif_clause', 'children': ['156', '161']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '161', 'type': 'block', 'children': ['162', '171', '193']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '165', 'type': 'dictionary', 'children': ['166']},{'id': '166', 'type': 'pair', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': '"v"'},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '170', 'type': 'integer', 'children': [], 'value': '0'},{'id': '171', 'type': 'if_statement', 'children': ['172', '184']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '179'], 'value': 'and'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '178'], 'value': '>'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': 'is'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'None', 'children': []},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '189', 'type': 'string', 'children': [], 'value': '"f"'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'if_statement', 'children': ['194', '200']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '199'], 'value': '=='},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '199', 'type': 'integer', 'children': [], 'value': '3'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '205', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '208', 'type': 'integer', 'children': [], 'value': '2'},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '214', 'type': 'dictionary', 'children': ['215']},{'id': '215', 'type': 'pair', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': '"v"'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'cell_objs'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'cell_obj'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'row_obj'},{'id': '228', 'type': 'dictionary', 'children': ['229']},{'id': '229', 'type': 'pair', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': '"c"'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'cell_objs'},{'id': '232', 'type': 'if_statement', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'cp'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '240']},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'row_obj'},{'id': '239', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'cp'},{'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': 'row_objs'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'row_obj'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'json_obj'},{'id': '251', 'type': 'dictionary', 'children': ['252', '255']},{'id': '252', 'type': 'pair', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': '"cols"'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'col_objs'},{'id': '255', 'type': 'pair', 'children': ['256', '257']},{'id': '256', 'type': 'string', 'children': [], 'value': '"rows"'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'row_objs'},{'id': '258', 'type': 'if_statement', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'custom_properties'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '268']},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'json_obj'},{'id': '267', 'type': 'string', 'children': [], 'value': '"p"'},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'custom_properties'},{'id': '271', 'type': 'return_statement', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'json_obj'} | def _ToJSonObj(self, columns_order=None, order_by=()):
if columns_order is None:
columns_order = [col["id"] for col in self.__columns]
col_dict = dict([(col["id"], col) for col in self.__columns])
col_objs = []
for col_id in columns_order:
col_obj = {"id": col_dict[col_id]["id"],
"label": col_dict[col_id]["label"],
"type": col_dict[col_id]["type"]}
if col_dict[col_id]["custom_properties"]:
col_obj["p"] = col_dict[col_id]["custom_properties"]
col_objs.append(col_obj)
row_objs = []
for row, cp in self._PreparedData(order_by):
cell_objs = []
for col in columns_order:
value = self.CoerceValue(row.get(col, None), col_dict[col]["type"])
if value is None:
cell_obj = None
elif isinstance(value, tuple):
cell_obj = {"v": value[0]}
if len(value) > 1 and value[1] is not None:
cell_obj["f"] = value[1]
if len(value) == 3:
cell_obj["p"] = value[2]
else:
cell_obj = {"v": value}
cell_objs.append(cell_obj)
row_obj = {"c": cell_objs}
if cp:
row_obj["p"] = cp
row_objs.append(row_obj)
json_obj = {"cols": col_objs, "rows": row_objs}
if self.custom_properties:
json_obj["p"] = self.custom_properties
return json_obj |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ToJSon'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '10', 'type': 'tuple', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '29', '44']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'encoded_response_str'},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'DataTableJSONEncoder'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_ToJSonObj'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'columns_order'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'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': 'encoded_response_str'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'encoded_response_str'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'encoded_response_str'} | def ToJSon(self, columns_order=None, order_by=()):
encoded_response_str = DataTableJSONEncoder().encode(self._ToJSonObj(columns_order, order_by))
if not isinstance(encoded_response_str, str):
return encoded_response_str.encode("utf-8")
return encoded_response_str |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_radix_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'block', 'children': ['9', '19', '23', '34', '69', '83']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '15'], 'value': '<='},{'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': 'L'},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'done_bucket'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '28']},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'integer', 'children': [], 'value': '255'},{'id': '34', 'type': 'for_statement', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '45', '53']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '>='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'done_bucket'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '67']},{'id': '57', 'type': 'attribute', 'children': ['58', '66']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '72', 'type': 'list_comprehension', 'children': ['73', '80']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_radix_sort'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'done_bucket'},{'id': '86', 'type': 'list_comprehension', 'children': ['87', '88', '91']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'blist'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'blist'} | def _radix_sort(L, i=0):
if len(L) <= 1:
return L
done_bucket = []
buckets = [ [] for x in range(255) ]
for s in L:
if i >= len(s):
done_bucket.append(s)
else:
buckets[ ord(s[i]) ].append(s)
buckets = [ _radix_sort(b, i + 1) for b in buckets ]
return done_bucket + [ b for blist in buckets for b in blist ] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fixed_legend_filter_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fixed_legend_filter_sort'},{'id': '6', 'type': 'block', 'children': ['7', '13', '29']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'allowed_values'},{'id': '10', 'type': 'list', 'children': ['11', '12'], 'value': '["TOP", "BOTTOM"]'},{'id': '11', 'type': 'string', 'children': [], 'value': '"TOP"'},{'id': '12', 'type': 'string', 'children': [], 'value': '"BOTTOM"'},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'not'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fixed_legend_filter_sort'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'allowed_values'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'raise_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"Invalid value for `fixed_legend_filter_sort` ({0}), must be one of {1}"'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fixed_legend_filter_sort'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'allowed_values'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_fixed_legend_filter_sort'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fixed_legend_filter_sort'} | def fixed_legend_filter_sort(self, fixed_legend_filter_sort):
allowed_values = ["TOP", "BOTTOM"]
if fixed_legend_filter_sort not in allowed_values:
raise ValueError(
"Invalid value for `fixed_legend_filter_sort` ({0}), must be one of {1}"
.format(fixed_legend_filter_sort, allowed_values)
)
self._fixed_legend_filter_sort = fixed_legend_filter_sort |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_table'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_columns'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '64', '81', '95']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_columns'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '22', '36', '59']},{'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': 'sort_columns'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'rows'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort_columns'},{'id': '36', 'type': 'elif_clause', 'children': ['37', '44']},{'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': 'sort_columns'},{'id': '41', 'type': 'tuple', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'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': 'rows'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'list_splat', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort_columns'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'assert_statement', 'children': ['62', '63']},{'id': '62', 'type': 'False', 'children': []},{'id': '63', 'type': 'string', 'children': [], 'value': '"Sort_columns must be int or list/tuple of int"'},{'id': '64', 'type': 'if_statement', 'children': ['65', '66', '74']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'},{'id': '72', 'type': 'string', 'children': [], 'value': "'\\n%s:'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "''"},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tabulate'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tabulate'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'tablefmt'},{'id': '94', 'type': 'string', 'children': [], 'value': "'simple'"},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "''"} | def print_table(title, headers, rows, sort_columns=None):
if sort_columns is not None:
if isinstance(sort_columns, int):
rows = sorted(rows, key=itemgetter(sort_columns))
elif isinstance(sort_columns, (list, tuple)):
rows = sorted(rows, key=itemgetter(*sort_columns))
else:
assert False, "Sort_columns must be int or list/tuple of int"
if title:
print('\n%s:' % title)
else:
print('')
print(tabulate.tabulate(rows, headers, tablefmt='simple'))
print('') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'formatted'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '96']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '9', 'type': 'string', 'children': [], 'value': '"Statistics (times in seconds, lengths in Bytes):\\n"'},{'id': '10', 'type': 'if_statement', 'children': ['11', '14', '90']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '14', 'type': 'block', 'children': ['15', '39', '43', '58', '75']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'snapshot'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21', '26', '36']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'snapshot'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'lambda', 'children': ['29', '31']},{'id': '29', 'type': 'lambda_parameters', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'avg_time'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '38', 'type': 'True', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'include_svr'},{'id': '42', 'type': 'False', 'children': []},{'id': '43', 'type': 'for_statement', 'children': ['44', '47', '48']},{'id': '44', 'type': 'pattern_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'snapshot'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_server_time_stored'},{'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': 'include_svr'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'if_statement', 'children': ['59', '60', '67']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'include_svr'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'OperationStatistic'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_formatted_header_w_svr'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'augmented_assignment', 'children': ['71', '72'], 'value': '+='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'OperationStatistic'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_formatted_header'},{'id': '75', 'type': 'for_statement', 'children': ['76', '79', '80']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'snapshot'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'formatted'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'include_svr'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'augmented_assignment', 'children': ['94', '95'], 'value': '+='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '95', 'type': 'string', 'children': [], 'value': '"Disabled"'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '101', 'type': 'argument_list', 'children': []} | def formatted(self):
ret = "Statistics (times in seconds, lengths in Bytes):\n"
if self.enabled:
snapshot = sorted(self.snapshot(),
key=lambda item: item[1].avg_time,
reverse=True)
include_svr = False
for name, stats in snapshot:
if stats._server_time_stored:
include_svr = True
if include_svr:
ret += OperationStatistic._formatted_header_w_svr
else:
ret += OperationStatistic._formatted_header
for name, stats in snapshot:
ret += stats.formatted(include_svr)
else:
ret += "Disabled"
return ret.strip() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_clusters'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'retry_contexts'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'all_clusters'},{'id': '8', 'type': 'block', 'children': ['9', '11', '15', '27', '120', '141', '156']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "''' return clusters sorted by load. '''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'possible_cluster_info'},{'id': '14', 'type': 'dictionary', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'all_clusters'},{'id': '27', 'type': 'while_statement', 'children': ['28', '32']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '30'], 'value': 'and'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'possible_cluster_info'},{'id': '32', 'type': 'block', 'children': ['33', '38', '101']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'wait_for_any_cluster'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'retry_contexts'},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '50']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'priority'"},{'id': '50', 'type': 'block', 'children': ['51', '59', '65', '71']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'retry_contexts'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'in_retry_wait'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'continue_statement', 'children': []},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'continue_statement', 'children': []},{'id': '71', 'type': 'try_statement', 'children': ['72', '89']},{'id': '72', 'type': 'block', 'children': ['73', '83']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'cluster_info'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_cluster_info'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'possible_cluster_info'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cluster_info'},{'id': '89', 'type': 'except_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'OsbsException'},{'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': 'ctx'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'try_again_later'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'find_cluster_retry_delay'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'augmented_assignment', 'children': ['103', '104'], 'value': '-='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'list_comprehension', 'children': ['108', '109', '112']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '112', 'type': 'if_clause', 'children': ['113']},{'id': '113', 'type': 'attribute', 'children': ['114', '119']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'retry_contexts'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '125', 'type': 'argument_list', 'children': ['126', '131']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'possible_cluster_info'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '133', 'type': 'lambda', 'children': ['134', '136']},{'id': '134', 'type': 'lambda_parameters', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '150', 'type': 'lambda', 'children': ['151', '153']},{'id': '151', 'type': 'lambda_parameters', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ret'} | def get_clusters(self, platform, retry_contexts, all_clusters):
''' return clusters sorted by load. '''
possible_cluster_info = {}
candidates = set(copy.copy(all_clusters))
while candidates and not possible_cluster_info:
wait_for_any_cluster(retry_contexts)
for cluster in sorted(candidates, key=attrgetter('priority')):
ctx = retry_contexts[cluster.name]
if ctx.in_retry_wait:
continue
if ctx.failed:
continue
try:
cluster_info = self.get_cluster_info(cluster, platform)
possible_cluster_info[cluster] = cluster_info
except OsbsException:
ctx.try_again_later(self.find_cluster_retry_delay)
candidates -= set([c for c in candidates if retry_contexts[c.name].failed])
ret = sorted(possible_cluster_info.values(), key=lambda c: c.cluster.priority)
ret = sorted(ret, key=lambda c: c.load)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_profile_names_and_default'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'type', 'children': ['5']},{'id': '5', 'type': '()', 'children': ['6']},{'id': '6', 'type': 'subscript', 'children': ['7', '10', '15']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '10', 'type': 'subscript', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'subscript', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Profile'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'with_statement', 'children': ['22', '32']},{'id': '22', 'type': 'with_clause', 'children': ['23']},{'id': '23', 'type': 'with_item', 'children': ['24']},{'id': '24', 'type': 'as_pattern', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ProfileStore'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'as_pattern_target', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'expression_list', 'children': ['35', '39']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'default'} | def get_profile_names_and_default() -> (
typing.Tuple[typing.Sequence[str], typing.Optional[Profile]]):
with ProfileStore.open() as config:
return sorted(config), config.default |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_all_commands'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'keyword_separator', 'children': []},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_pager'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '20', '37', '53', '57', '174']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'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': 'parent_parser'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_get_formatter'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'command_names'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '36']},{'id': '27', 'type': 'attribute', 'children': ['28', '35']},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parent_parser'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'subparsers'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'max_name_len'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '52'], 'value': '+'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '49']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'command_names'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '56', 'type': 'string', 'children': [], 'value': '""'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'command_names'},{'id': '60', 'type': 'block', 'children': ['61', '73', '82', '95', '165']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '64', 'type': 'subscript', 'children': ['65', '72']},{'id': '65', 'type': 'attribute', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'parent_parser'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'subparsers'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'extra_padding'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '-'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'max_name_len'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'},{'id': '86', 'type': 'string', 'children': [], 'value': "'%s%s%s'"},{'id': '87', 'type': 'tuple', 'children': ['88', '89', '92']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '*'},{'id': '90', 'type': 'string', 'children': [], 'value': "' '"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'extra_padding'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '95', 'type': 'while_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '>'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_width'},{'id': '104', 'type': 'block', 'children': ['105', '117', '125']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'textwrap'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'wrap'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_width'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '%'},{'id': '121', 'type': 'string', 'children': [], 'value': '"%s\\n"'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'if_statement', 'children': ['126', '132', '159']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '>'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'block', 'children': ['133', '146']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '143'], 'value': '+'},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '*'},{'id': '141', 'type': 'string', 'children': [], 'value': "' '"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'max_name_len'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "' '"},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '156', 'type': 'slice', 'children': ['157', '158']},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'colon', 'children': []},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'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': 'command_line'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'if_statement', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '%'},{'id': '172', 'type': 'string', 'children': [], 'value': '"%s\\n"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'command_line'},{'id': '174', 'type': 'if_statement', 'children': ['175', '176', '187']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'no_pager'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '183', 'type': 'slice', 'children': ['184', '185']},{'id': '184', 'type': 'colon', 'children': []},{'id': '185', 'type': 'unary_operator', 'children': ['186'], 'value': '-'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'else_clause', 'children': ['188']},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'print_with_pager'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '195', 'type': 'slice', 'children': ['196', '197']},{'id': '196', 'type': 'colon', 'children': []},{'id': '197', 'type': 'unary_operator', 'children': ['198'], 'value': '-'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'} | def print_all_commands(self, *, no_pager=False):
formatter = self.parent_parser._get_formatter()
command_names = sorted(self.parent_parser.subparsers.choices.keys())
max_name_len = max([len(name) for name in command_names]) + 1
commands = ""
for name in command_names:
command = self.parent_parser.subparsers.choices[name]
extra_padding = max_name_len - len(name)
command_line = '%s%s%s' % (
name, ' ' * extra_padding, command.description)
while len(command_line) > formatter._width:
lines = textwrap.wrap(command_line, formatter._width)
commands += "%s\n" % lines[0]
if len(lines) > 1:
lines[1] = (' ' * max_name_len) + lines[1]
command_line = ' '.join(lines[1:])
else:
command_line = None
if command_line:
commands += "%s\n" % command_line
if no_pager:
print(commands[:-1])
else:
print_with_pager(commands[:-1]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank_dated_files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '25']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'descending'} | def rank_dated_files(pattern, dir, descending=True):
files = glob.glob(op.join(dir, pattern))
return sorted(files, reverse=descending) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'best_structures'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '13', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '22', '30', '40', '62', '216', '225', '248']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '21', 'type': 'string', 'children': [], 'value': "''"},{'id': '22', 'type': 'if_statement', 'children': ['23', '25']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '29', 'type': 'string', 'children': [], 'value': "''"},{'id': '30', 'type': 'if_statement', 'children': ['31', '35']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '34'], 'value': 'and'},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'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': 'outname'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '40', 'type': 'if_statement', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '42', 'type': 'block', 'children': ['43', '53']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'{}.json'"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '62', 'type': 'if_statement', 'children': ['63', '77', '111']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ssbio'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '77', 'type': 'block', 'children': ['78', '99']},{'id': '78', 'type': 'with_statement', 'children': ['79', '89']},{'id': '79', 'type': 'with_clause', 'children': ['80']},{'id': '80', 'type': 'with_item', 'children': ['81']},{'id': '81', 'type': 'as_pattern', 'children': ['82', '87']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '86', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '87', 'type': 'as_pattern_target', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'{}: loaded existing json file'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '111', 'type': 'else_clause', 'children': ['112']},{'id': '112', 'type': 'block', 'children': ['113', '133', '181']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '120', 'type': 'argument_list', 'children': ['121', '127']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': "'https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/{}'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '129', 'type': 'dictionary', 'children': ['130']},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '132', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '133', 'type': 'if_statement', 'children': ['134', '139', '159']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '138'], 'value': '=='},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '138', 'type': 'integer', 'children': [], 'value': '404'},{'id': '139', 'type': 'block', 'children': ['140', '152']},{'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': 'debug'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'{}: 404 returned, probably no structures available.'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '155', 'type': 'dictionary', 'children': ['156']},{'id': '156', 'type': 'pair', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '158', 'type': 'dictionary', 'children': []},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161', '173']},{'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': 'log'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': "'{}: Obtained best structures'"},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '180', 'type': 'argument_list', 'children': []},{'id': '181', 'type': 'if_statement', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '183', 'type': 'block', 'children': ['184', '204']},{'id': '184', 'type': 'with_statement', 'children': ['185', '195']},{'id': '185', 'type': 'with_clause', 'children': ['186']},{'id': '186', 'type': 'with_item', 'children': ['187']},{'id': '187', 'type': 'as_pattern', 'children': ['188', '193']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '192', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '193', 'type': 'as_pattern_target', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'json'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': "'{}: Saved json file of best structures'"},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '219', 'type': 'subscript', 'children': ['220', '224']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '225', 'type': 'if_statement', 'children': ['226', '229']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '!='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'for_statement', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'if_statement', 'children': ['235', '240']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '239'], 'value': '<'},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '238', 'type': 'string', 'children': [], 'value': "'coverage'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '248', 'type': 'return_statement', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'data'} | def best_structures(uniprot_id, outname=None, outdir=None, seq_ident_cutoff=0.0, force_rerun=False):
outfile = ''
if not outdir:
outdir = ''
if not outname and outdir:
outname = uniprot_id
if outname:
outname = op.join(outdir, outname)
outfile = '{}.json'.format(outname)
if not ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
with open(outfile, 'r') as f:
raw_data = json.load(f)
log.debug('{}: loaded existing json file'.format(uniprot_id))
else:
response = requests.get('https://www.ebi.ac.uk/pdbe/api/mappings/best_structures/{}'.format(uniprot_id),
data={'key': 'value'})
if response.status_code == 404:
log.debug('{}: 404 returned, probably no structures available.'.format(uniprot_id))
raw_data = {uniprot_id: {}}
else:
log.debug('{}: Obtained best structures'.format(uniprot_id))
raw_data = response.json()
if outfile:
with open(outfile, 'w') as f:
json.dump(raw_data, f)
log.debug('{}: Saved json file of best structures'.format(uniprot_id))
data = dict(raw_data)[uniprot_id]
if seq_ident_cutoff != 0:
for result in data:
if result['coverage'] < seq_ident_cutoff:
data.remove(result)
return data |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_uniprot_to_pdb'},{'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': 'seq_ident_cutoff'},{'id': '7', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '37', '45', '65', '95', '114', '147', '151', '308']},{'id': '15', 'type': 'if_statement', 'children': ['16', '20']},{'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': 'representative_sequence'},{'id': '20', 'type': 'block', 'children': ['21', '35']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': "'{}: no representative sequence set, cannot use best structures API'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'representative_sequence'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'uniprot'},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '48', 'type': 'block', 'children': ['49', '63']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'{}: no representative UniProt ID set, cannot use best structures API'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'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': 'id'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '69', 'type': 'block', 'children': ['70', '84']},{'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': 'log'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '\'{}: "-" detected in UniProt ID, isoform specific sequences are ignored with best structures API\''},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '87', 'type': 'subscript', 'children': ['88', '94']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'if_statement', 'children': ['96', '98']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '98', 'type': 'block', 'children': ['99', '105']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sequence_dir'},{'id': '105', 'type': 'if_statement', 'children': ['106', '108']},{'id': '106', 'type': 'not_operator', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'raise_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'Output directory must be specified'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '117', 'type': 'call', 'children': ['118', '125']},{'id': '118', 'type': 'attribute', 'children': ['119', '124']},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ssbio'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'databases'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pdb'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127', '138', '141', '144']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'outname'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'{}_best_structures'"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'custom_slugify'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'new_pdbs'},{'id': '150', 'type': 'list', 'children': [], 'value': '[]'},{'id': '151', 'type': 'if_statement', 'children': ['152', '153', '291']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '153', 'type': 'block', 'children': ['154', '158', '272']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '161']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'best_structure'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '161', 'type': 'block', 'children': ['162', '175', '182', '191', '205', '212', '218', '227', '237', '248', '258', '268']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'currpdb'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'best_structure'},{'id': '172', 'type': 'string', 'children': [], 'value': "'pdb_id'"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '174', 'type': 'argument_list', 'children': []},{'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': 'new_pdbs'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'currpdb'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'currchain'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'best_structure'},{'id': '190', 'type': 'string', 'children': [], 'value': "'chain_id'"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'new_pdb'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'load_pdb'},{'id': '198', 'type': 'argument_list', 'children': ['199', '202']},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'pdb_id'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'currpdb'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'mapped_chains'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'currchain'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'new_pdb'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'add_chain_ids'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'currchain'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'pdb_specific_keys'},{'id': '215', 'type': 'list', 'children': ['216', '217'], 'value': "['experimental_method', 'resolution']"},{'id': '216', 'type': 'string', 'children': [], 'value': "'experimental_method'"},{'id': '217', 'type': 'string', 'children': [], 'value': "'resolution'"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'chain_specific_keys'},{'id': '221', 'type': 'list', 'children': ['222', '223', '224', '225', '226'], 'value': "['coverage', 'start', 'end', 'unp_start', 'unp_end']"},{'id': '222', 'type': 'string', 'children': [], 'value': "'coverage'"},{'id': '223', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '224', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '225', 'type': 'string', 'children': [], 'value': "'unp_start'"},{'id': '226', 'type': 'string', 'children': [], 'value': "'unp_end'"},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'new_pdb'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'best_structure'},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'only_keys'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'pdb_specific_keys'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'new_chain'},{'id': '240', 'type': 'call', 'children': ['241', '246']},{'id': '241', 'type': 'attribute', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'new_pdb'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'chains'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get_by_id'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'currchain'},{'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': 'new_chain'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'best_structure'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'only_keys'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'chain_specific_keys'},{'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': 'new_chain'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'dictionary', 'children': ['265']},{'id': '265', 'type': 'pair', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'rank'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'augmented_assignment', 'children': ['270', '271'], 'value': '+='},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': "'{}, {}: {} PDB/chain pairs mapped'"},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '282', 'type': 'argument_list', 'children': ['283', '286', '287']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '291', 'type': 'else_clause', 'children': ['292']},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'string', 'children': [], 'value': "'{}, {}: no PDB/chain pairs mapped'"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '303', 'type': 'argument_list', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '308', 'type': 'return_statement', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'new_pdbs'} | def map_uniprot_to_pdb(self, seq_ident_cutoff=0.0, outdir=None, force_rerun=False):
if not self.representative_sequence:
log.error('{}: no representative sequence set, cannot use best structures API'.format(self.id))
return None
uniprot_id = self.representative_sequence.uniprot
if not uniprot_id:
log.error('{}: no representative UniProt ID set, cannot use best structures API'.format(self.id))
return None
if '-' in uniprot_id:
log.debug('{}: "-" detected in UniProt ID, isoform specific sequences are ignored with best structures API'.format(self.id))
uniprot_id = uniprot_id.split('-')[0]
if not outdir:
outdir = self.sequence_dir
if not outdir:
raise ValueError('Output directory must be specified')
best_structures = ssbio.databases.pdb.best_structures(uniprot_id,
outname='{}_best_structures'.format(custom_slugify(uniprot_id)),
outdir=outdir,
seq_ident_cutoff=seq_ident_cutoff,
force_rerun=force_rerun)
new_pdbs = []
if best_structures:
rank = 1
for best_structure in best_structures:
currpdb = str(best_structure['pdb_id'].lower())
new_pdbs.append(currpdb)
currchain = str(best_structure['chain_id'])
new_pdb = self.load_pdb(pdb_id=currpdb, mapped_chains=currchain)
new_pdb.add_chain_ids(currchain)
pdb_specific_keys = ['experimental_method', 'resolution']
chain_specific_keys = ['coverage', 'start', 'end', 'unp_start', 'unp_end']
new_pdb.update(best_structure, only_keys=pdb_specific_keys)
new_chain = new_pdb.chains.get_by_id(currchain)
new_chain.update(best_structure, only_keys=chain_specific_keys)
new_chain.update({'rank': rank})
rank += 1
log.debug('{}, {}: {} PDB/chain pairs mapped'.format(self.id, uniprot_id, len(best_structures)))
else:
log.debug('{}, {}: no PDB/chain pairs mapped'.format(self.id, uniprot_id))
return new_pdbs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_uniprot_to_pdb'},{'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': 'seq_ident_cutoff'},{'id': '7', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '61', '68', '85', '89', '193', '216']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'all_representative_uniprots'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'genes_with_a_representative_sequence'},{'id': '24', 'type': 'block', 'children': ['25', '35']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'representative_sequence'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'uniprot'},{'id': '35', 'type': 'if_statement', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '37', 'type': 'block', 'children': ['38', '54']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'},{'id': '40', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'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': 'uniprot_id'},{'id': '46', 'type': 'subscript', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'all_representative_uniprots'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'Mapping UniProt IDs --> PDB IDs...'"},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'uniprots_to_pdbs'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bs_unip'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79', '82']},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '78', 'type': 'string', 'children': [], 'value': "'ACC'"},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'to'},{'id': '81', 'type': 'string', 'children': [], 'value': "'PDB_ID'"},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'all_representative_uniprots'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '97']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'tqdm'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'genes_with_a_representative_sequence'},{'id': '97', 'type': 'block', 'children': ['98', '108']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '101', 'type': 'attribute', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'representative_sequence'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'uniprot'},{'id': '108', 'type': 'if_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '110', 'type': 'block', 'children': ['111', '127']},{'id': '111', 'type': 'if_statement', 'children': ['112', '115']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'in'},{'id': '113', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '119', 'type': 'subscript', 'children': ['120', '126']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131', '176']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'in'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'uniprots_to_pdbs'},{'id': '131', 'type': 'block', 'children': ['132', '151']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '135', 'type': 'call', 'children': ['136', '141']},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'protein'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'map_uniprot_to_pdb'},{'id': '141', 'type': 'argument_list', 'children': ['142', '145', '148']},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'seq_ident_cutoff'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'outdir'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'force_rerun'},{'id': '151', 'type': 'if_statement', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '153', 'type': 'block', 'children': ['154', '158']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': "'{}: {} PDBs mapped'"},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'best_structures'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': "'{}, {}: no PDBs available'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '188', 'type': 'argument_list', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'},{'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': 'log'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'{}/{}: number of genes with at least one experimental structure'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '203', 'type': 'argument_list', 'children': ['204', '210']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'genes_with_experimental_structures'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'genes'},{'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': 'log'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': '\'Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.\''} | def map_uniprot_to_pdb(self, seq_ident_cutoff=0.0, outdir=None, force_rerun=False):
all_representative_uniprots = []
for g in self.genes_with_a_representative_sequence:
uniprot_id = g.protein.representative_sequence.uniprot
if uniprot_id:
if '-' in uniprot_id:
uniprot_id = uniprot_id.split('-')[0]
all_representative_uniprots.append(uniprot_id)
log.info('Mapping UniProt IDs --> PDB IDs...')
uniprots_to_pdbs = bs_unip.mapping(fr='ACC', to='PDB_ID', query=all_representative_uniprots)
counter = 0
for g in tqdm(self.genes_with_a_representative_sequence):
uniprot_id = g.protein.representative_sequence.uniprot
if uniprot_id:
if '-' in uniprot_id:
uniprot_id = uniprot_id.split('-')[0]
if uniprot_id in uniprots_to_pdbs:
best_structures = g.protein.map_uniprot_to_pdb(seq_ident_cutoff=seq_ident_cutoff, outdir=outdir, force_rerun=force_rerun)
if best_structures:
counter += 1
log.debug('{}: {} PDBs mapped'.format(g.id, len(best_structures)))
else:
log.debug('{}, {}: no PDBs available'.format(g.id, uniprot_id))
log.info('{}/{}: number of genes with at least one experimental structure'.format(len(self.genes_with_experimental_structures),
len(self.genes)))
log.info('Completed UniProt --> best PDB mapping. See the "df_pdb_ranking" attribute for a summary dataframe.') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_properties_by_type'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '11', 'type': 'string', 'children': [], 'value': '""'},{'id': '12', 'type': 'block', 'children': ['13', '20', '58', '62', '173']},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'augmented_assignment', 'children': ['18', '19'], 'value': '+='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '19', 'type': 'string', 'children': [], 'value': '"."'},{'id': '20', 'type': 'if_statement', 'children': ['21', '26']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '51']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '=='},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '30', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '44'], 'value': '-'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'MAPPING_NAME_TYPE'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'list', 'children': ['48', '49', '50'], 'value': '["nested", "multi_field", "multifield"]'},{'id': '48', 'type': 'string', 'children': [], 'value': '"nested"'},{'id': '49', 'type': 'string', 'children': [], 'value': '"multi_field"'},{'id': '50', 'type': 'string', 'children': [], 'value': '"multifield"'},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '56', 'type': 'list', 'children': ['57'], 'value': '[type]'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '74']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '66', 'type': 'argument_list', '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': 'properties'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'block', 'children': ['75', '137', '142']},{'id': '75', 'type': 'if_statement', 'children': ['76', '81', '96']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': 'in'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '81', 'type': 'block', 'children': ['82', '95']},{'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': 'properties'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'tuple', 'children': ['89', '94']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '95', 'type': 'continue_statement', 'children': []},{'id': '96', 'type': 'elif_clause', 'children': ['97', '122']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '111'], 'value': 'and'},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '104'], 'value': 'and'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '=='},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '103', 'type': 'string', 'children': [], 'value': '"multi_field"'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': 'in'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '121'], 'value': 'in'},{'id': '112', 'type': 'attribute', 'children': ['113', '120']},{'id': '113', 'type': 'subscript', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '122', 'type': 'block', 'children': ['123', '136']},{'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': 'properties'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'tuple', 'children': ['130', '135']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '136', 'type': 'continue_statement', 'children': []},{'id': '137', 'type': 'if_statement', 'children': ['138', '140']},{'id': '138', 'type': 'not_operator', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'continue_statement', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '150']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': 'in'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '147', 'type': 'list', 'children': ['148', '149'], 'value': '["nested", "object"]'},{'id': '148', 'type': 'string', 'children': [], 'value': '"nested"'},{'id': '149', 'type': 'string', 'children': [], 'value': '"object"'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'get_properties_by_type'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163', '166']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '+'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'parent_path'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'properties'} | def get_properties_by_type(self, type, recursive=True, parent_path=""):
if parent_path:
parent_path += "."
if isinstance(type, str):
if type == "*":
type = set(MAPPING_NAME_TYPE.keys()) - set(["nested", "multi_field", "multifield"])
else:
type = [type]
properties = []
for prop in list(self.properties.values()):
if prop.type in type:
properties.append((parent_path + prop.name, prop))
continue
elif prop.type == "multi_field" and prop.name in prop.fields and prop.fields[prop.name].type in type:
properties.append((parent_path + prop.name, prop))
continue
if not recursive:
continue
if prop.type in ["nested", "object"]:
properties.extend(
prop.get_properties_by_type(type, recursive=recursive, parent_path=parent_path + prop.name))
return sorted(properties) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '8', 'type': 'block', 'children': ['9', '42', '52']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'in'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'keyOrder'},{'id': '15', 'type': 'block', 'children': ['16', '27', '33']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'keyOrder'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'delete_statement', 'children': ['28']},{'id': '28', 'type': 'subscript', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keyOrder'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'augmented_assignment', 'children': ['40', '41'], 'value': '-='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'keyOrder'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'SortedDict'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '__setitem__'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'} | def insert(self, index, key, value):
if key in self.keyOrder:
n = self.keyOrder.index(key)
del self.keyOrder[n]
if n < index:
index -= 1
self.keyOrder.insert(index, key)
super(SortedDict, self).__setitem__(key, value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_qualified_edges'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '8', 'type': 'type_parameter', 'children': ['9']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'EdgeTuple'},{'id': '11', 'type': 'block', 'children': ['12', '56']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'qualified_edges'},{'id': '15', 'type': 'generator_expression', 'children': ['16', '21', '38']},{'id': '16', 'type': 'tuple', 'children': ['17', '18', '19', '20']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '27']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24', '25', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '31', 'type': 'argument_list', 'children': ['32', '35']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'if_clause', 'children': ['39']},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '48'], 'value': 'and'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'has_edge_citation'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'has_edge_evidence'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'qualified_edges'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_sort_qualified_edges_helper'} | def sort_qualified_edges(graph) -> Iterable[EdgeTuple]:
qualified_edges = (
(u, v, k, d)
for u, v, k, d in graph.edges(keys=True, data=True)
if graph.has_edge_citation(u, v, k) and graph.has_edge_evidence(u, v, k)
)
return sorted(qualified_edges, key=_sort_qualified_edges_helper) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_citation_sort_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'EdgeTuple'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': '\'"{}", "{}"\''},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '16', 'type': 'argument_list', 'children': ['17', '24']},{'id': '17', 'type': 'subscript', 'children': ['18', '23']},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '21', 'type': 'integer', 'children': [], 'value': '3'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'CITATION'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'CITATION_TYPE'},{'id': '24', 'type': 'subscript', 'children': ['25', '30']},{'id': '25', 'type': 'subscript', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '28', 'type': 'integer', 'children': [], 'value': '3'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'CITATION'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'CITATION_REFERENCE'} | def _citation_sort_key(t: EdgeTuple) -> str:
return '"{}", "{}"'.format(t[3][CITATION][CITATION_TYPE], t[3][CITATION][CITATION_REFERENCE]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_pubmed_identifiers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pmids'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'generic_type', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '15', 'type': 'type_parameter', 'children': ['16']},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'set_comprehension', 'children': ['24', '32']},{'id': '24', 'type': 'call', 'children': ['25', '31']},{'id': '25', 'type': 'attribute', 'children': ['26', '30']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pmid'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pmids'} | def clean_pubmed_identifiers(pmids: Iterable[str]) -> List[str]:
return sorted({str(pmid).strip() for pmid in pmids}) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_dump'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '31']},{'id': '10', 'type': 'attribute', 'children': ['11', '30']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sha512'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '28']},{'id': '17', 'type': 'attribute', 'children': ['18', '27']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '31', 'type': 'argument_list', 'children': []} | def hash_dump(data) -> str:
return hashlib.sha512(json.dumps(data, sort_keys=True).encode('utf-8')).hexdigest() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'yield_sorted_by_type'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'typelist'},{'id': '6', 'type': 'block', 'children': ['7', '40']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'decorate'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fun'},{'id': '11', 'type': 'block', 'children': ['12', '38']},{'id': '12', 'type': 'decorated_definition', 'children': ['13', '18']},{'id': '13', 'type': 'decorator', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'fun'},{'id': '18', 'type': 'function_definition', 'children': ['19', '20', '25']},{'id': '19', 'type': 'function_name', 'children': [], 'value': 'decorated'},{'id': '20', 'type': 'parameters', 'children': ['21', '23']},{'id': '21', 'type': 'list_splat_pattern', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '23', 'type': 'dictionary_splat_pattern', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'iterate_by_type'},{'id': '29', 'type': 'argument_list', 'children': ['30', '37']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fun'},{'id': '32', 'type': 'argument_list', 'children': ['33', '35']},{'id': '33', 'type': 'list_splat', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '35', 'type': 'dictionary_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'typelist'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'decorated'},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'decorate'} | def yield_sorted_by_type(*typelist):
def decorate(fun):
@wraps(fun)
def decorated(*args, **kwds):
return iterate_by_type(fun(*args, **kwds), typelist)
return decorated
return decorate |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_route_timetable'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': '"Feed"'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'route_id'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dates'},{'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': 'str'},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '22', 'type': 'block', 'children': ['23', '32', '42', '56', '70', '79', '83', '163', '172']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'restrict_dates'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '32', 'type': 'if_statement', 'children': ['33', '35']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'trips'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stop_times'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '59', 'type': 'call', 'children': ['60', '69']},{'id': '60', 'type': 'attribute', 'children': ['61', '68']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '66', 'type': 'string', 'children': [], 'value': '"route_id"'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'route_id'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'compute_trip_activity'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '86', 'type': 'block', 'children': ['87', '100', '117', '123', '138', '156']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '90', 'type': 'subscript', 'children': ['91', '94', '99']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'string', 'children': [], 'value': '"trip_id"'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '103', 'type': 'call', 'children': ['104', '116']},{'id': '104', 'type': 'attribute', 'children': ['105', '115']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '111', 'type': 'string', 'children': [], 'value': '"trip_id"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '127', 'type': 'string', 'children': [], 'value': '"dt"'},{'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': 'f'},{'id': '132', 'type': 'string', 'children': [], 'value': '"departure_time"'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'fillna'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '137', 'type': 'string', 'children': [], 'value': '"ffill"'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '142', 'type': 'string', 'children': [], 'value': '"min_dt"'},{'id': '143', 'type': 'call', 'children': ['144', '154']},{'id': '144', 'type': 'attribute', 'children': ['145', '153']},{'id': '145', 'type': 'subscript', 'children': ['146', '152']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': '"trip_id"'},{'id': '152', 'type': 'string', 'children': [], 'value': '"dt"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'transform'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'min'},{'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': 'frames'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '185']},{'id': '174', 'type': 'attribute', 'children': ['175', '184']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'list', 'children': ['181', '182', '183'], 'value': '["date", "min_dt", "stop_sequence"]'},{'id': '181', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '182', 'type': 'string', 'children': [], 'value': '"min_dt"'},{'id': '183', 'type': 'string', 'children': [], 'value': '"stop_sequence"'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '185', 'type': 'argument_list', 'children': ['186', '189']},{'id': '186', 'type': 'list', 'children': ['187', '188'], 'value': '["min_dt", "dt"]'},{'id': '187', 'type': 'string', 'children': [], 'value': '"min_dt"'},{'id': '188', 'type': 'string', 'children': [], 'value': '"dt"'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'} | def build_route_timetable(
feed: "Feed", route_id: str, dates: List[str]
) -> DataFrame:
dates = feed.restrict_dates(dates)
if not dates:
return pd.DataFrame()
t = pd.merge(feed.trips, feed.stop_times)
t = t[t["route_id"] == route_id].copy()
a = feed.compute_trip_activity(dates)
frames = []
for date in dates:
ids = a.loc[a[date] == 1, "trip_id"]
f = t[t["trip_id"].isin(ids)].copy()
f["date"] = date
f["dt"] = f["departure_time"].fillna(method="ffill")
f["min_dt"] = f.groupby("trip_id")["dt"].transform(min)
frames.append(f)
f = pd.concat(frames)
return f.sort_values(["date", "min_dt", "stop_sequence"]).drop(
["min_dt", "dt"], axis=1
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'almost_equal'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '23', '31']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'or'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33', '62', '91']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '58']},{'id': '38', 'type': 'attribute', 'children': ['39', '57']},{'id': '39', 'type': 'call', 'children': ['40', '50']},{'id': '40', 'type': 'attribute', 'children': ['41', '49']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '61', 'type': 'True', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '65', 'type': '()', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '87']},{'id': '67', 'type': 'attribute', 'children': ['68', '86']},{'id': '68', 'type': 'call', 'children': ['69', '79']},{'id': '69', 'type': 'attribute', 'children': ['70', '78']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '90', 'type': 'True', 'children': []},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'equals'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'G'} | def almost_equal(f: DataFrame, g: DataFrame) -> bool:
if f.empty or g.empty:
return f.equals(g)
else:
F = (
f.sort_index(axis=1)
.sort_values(list(f.columns))
.reset_index(drop=True)
)
G = (
g.sort_index(axis=1)
.sort_values(list(g.columns))
.reset_index(drop=True)
)
return F.equals(G) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_stop_timetable'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': '"Feed"'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dates'},{'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': 'str'},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '22', 'type': 'block', 'children': ['23', '32', '42', '56', '70', '79', '83', '130', '139']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'restrict_dates'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '32', 'type': 'if_statement', 'children': ['33', '35']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'trips'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stop_times'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '59', 'type': 'call', 'children': ['60', '69']},{'id': '60', 'type': 'attribute', 'children': ['61', '68']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '66', 'type': 'string', 'children': [], 'value': '"stop_id"'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'stop_id'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'feed'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'compute_trip_activity'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '86', 'type': 'block', 'children': ['87', '100', '117', '123']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '90', 'type': 'subscript', 'children': ['91', '94', '99']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'string', 'children': [], 'value': '"trip_id"'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '103', 'type': 'call', 'children': ['104', '116']},{'id': '104', 'type': 'attribute', 'children': ['105', '115']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '111', 'type': 'string', 'children': [], 'value': '"trip_id"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'isin'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'date'},{'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': 'frames'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'frames'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'list', 'children': ['146', '147'], 'value': '["date", "departure_time"]'},{'id': '146', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '147', 'type': 'string', 'children': [], 'value': '"departure_time"'} | def build_stop_timetable(
feed: "Feed", stop_id: str, dates: List[str]
) -> DataFrame:
dates = feed.restrict_dates(dates)
if not dates:
return pd.DataFrame()
t = pd.merge(feed.trips, feed.stop_times)
t = t[t["stop_id"] == stop_id].copy()
a = feed.compute_trip_activity(dates)
frames = []
for date in dates:
ids = a.loc[a[date] == 1, "trip_id"]
f = t[t["trip_id"].isin(ids)].copy()
f["date"] = date
frames.append(f)
f = pd.concat(frames)
return f.sort_values(["date", "departure_time"]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_unit_property_names'},{'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': 'unit_id'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '63']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'''Get a list of property names for a given unit, or for all units if unit_id is None\n Parameters\n ----------\n unit_id: int\n The unit id for which the property names will be returned\n If None (default), will return property names for all units\n Returns\n ----------\n property_names\n The list of property names from the specified unit(s)\n '''"},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '20', '48', '61']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '27']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_unit_ids'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '37']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_unit_property_names'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '63', 'type': 'if_statement', 'children': ['64', '73', '127']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '68', 'type': 'tuple', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'integer'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '82', '115']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_unit_ids'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'block', 'children': ['83', '98', '113']},{'id': '83', 'type': 'if_statement', 'children': ['84', '89']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'not'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_unit_properties'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '97']},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_unit_properties'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '97', 'type': 'dictionary', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '112']},{'id': '105', 'type': 'attribute', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_unit_properties'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'return_statement', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'property_names'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'raise_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '126'], 'value': '+'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '126', 'type': 'string', 'children': [], 'value': '" is not a valid unit_id"'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '138'], 'value': '+'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '138', 'type': 'string', 'children': [], 'value': '" must be an int"'} | def get_unit_property_names(self, unit_id=None):
'''Get a list of property names for a given unit, or for all units if unit_id is None
Parameters
----------
unit_id: int
The unit id for which the property names will be returned
If None (default), will return property names for all units
Returns
----------
property_names
The list of property names from the specified unit(s)
'''
if unit_id is None:
property_names = []
for unit_id in self.get_unit_ids():
curr_property_names = self.get_unit_property_names(unit_id)
for curr_property_name in curr_property_names:
property_names.append(curr_property_name)
property_names = sorted(list(set(property_names)))
return property_names
if isinstance(unit_id, (int, np.integer)):
if unit_id in self.get_unit_ids():
if unit_id not in self._unit_properties:
self._unit_properties[unit_id] = {}
property_names = sorted(self._unit_properties[unit_id].keys())
return property_names
else:
raise ValueError(str(unit_id) + " is not a valid unit_id")
else:
raise ValueError(str(unit_id) + " must be an int") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy_unit_properties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '25']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''Copy unit properties from another sorting extractor to the current\n sorting extractor.\n Parameters\n ----------\n sorting: SortingExtractor\n The sorting extractor from which the properties will be copied\n unit_ids: (array_like, int)\n The list (or single value) of unit_ids for which the properties will be copied.\n '''"},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_unit_ids'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '31', '76']},{'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': 'unit_ids'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'block', 'children': ['32', '43']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_unit_property_names'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '46', 'type': 'block', 'children': ['47', '61']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_unit_property'},{'id': '54', 'type': 'argument_list', 'children': ['55', '58']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set_unit_property'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70', '73']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '81', 'type': 'block', 'children': ['82', '93']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_unit_property_names'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'curr_property_names'},{'id': '96', 'type': 'block', 'children': ['97', '111']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_unit_property'},{'id': '104', 'type': 'argument_list', 'children': ['105', '108']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'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': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'set_unit_property'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120', '123']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'property_name'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'curr_property_name'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'} | def copy_unit_properties(self, sorting, unit_ids=None):
'''Copy unit properties from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the properties will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the properties will be copied.
'''
if unit_ids is None:
unit_ids = sorting.get_unit_ids()
if isinstance(unit_ids, int):
curr_property_names = sorting.get_unit_property_names(unit_id=unit_ids)
for curr_property_name in curr_property_names:
value = sorting.get_unit_property(unit_id=unit_ids, property_name=curr_property_name)
self.set_unit_property(unit_id=unit_ids, property_name=curr_property_name, value=value)
else:
for unit_id in unit_ids:
curr_property_names = sorting.get_unit_property_names(unit_id=unit_id)
for curr_property_name in curr_property_names:
value = sorting.get_unit_property(unit_id=unit_id, property_name=curr_property_name)
self.set_unit_property(unit_id=unit_id, property_name=curr_property_name, value=value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy_unit_spike_features'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '25']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''Copy unit spike features from another sorting extractor to the current\n sorting extractor.\n Parameters\n ----------\n sorting: SortingExtractor\n The sorting extractor from which the spike features will be copied\n unit_ids: (array_like, int)\n The list (or single value) of unit_ids for which the spike features will be copied.\n def get_unit_spike_features(self, unit_id, feature_name, start_frame=None, end_frame=None):\n '''"},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_unit_ids'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '31', '76']},{'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': 'unit_ids'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '31', 'type': 'block', 'children': ['32', '43']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'curr_feature_names'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_feature_names'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'curr_feature_names'},{'id': '46', 'type': 'block', 'children': ['47', '61']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_features'},{'id': '54', 'type': 'argument_list', 'children': ['55', '58']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set_unit_spike_features'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70', '73']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '81', 'type': 'block', 'children': ['82', '93']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'curr_feature_names'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_feature_names'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'curr_feature_names'},{'id': '96', 'type': 'block', 'children': ['97', '111']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_features'},{'id': '104', 'type': 'argument_list', 'children': ['105', '108']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'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': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'set_unit_spike_features'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120', '123']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'curr_feature_name'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'} | def copy_unit_spike_features(self, sorting, unit_ids=None):
'''Copy unit spike features from another sorting extractor to the current
sorting extractor.
Parameters
----------
sorting: SortingExtractor
The sorting extractor from which the spike features will be copied
unit_ids: (array_like, int)
The list (or single value) of unit_ids for which the spike features will be copied.
def get_unit_spike_features(self, unit_id, feature_name, start_frame=None, end_frame=None):
'''
if unit_ids is None:
unit_ids = sorting.get_unit_ids()
if isinstance(unit_ids, int):
curr_feature_names = sorting.get_unit_spike_feature_names(unit_id=unit_ids)
for curr_feature_name in curr_feature_names:
value = sorting.get_unit_spike_features(unit_id=unit_ids, feature_name=curr_feature_name)
self.set_unit_spike_features(unit_id=unit_ids, feature_name=curr_feature_name, value=value)
else:
for unit_id in unit_ids:
curr_feature_names = sorting.get_unit_spike_feature_names(unit_id=unit_id)
for curr_feature_name in curr_feature_names:
value = sorting.get_unit_spike_features(unit_id=unit_id, feature_name=curr_feature_name)
self.set_unit_spike_features(unit_id=unit_id, feature_name=curr_feature_name, value=value) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_units'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '6', 'type': 'block', 'children': ['7', '9', '13', '42', '46']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''This function merges two roots from the curation tree according to the given unit_ids. It creates a new unit_id and root\n that has the merged roots as children.\n Parameters\n ----------\n unit_ids: list\n The unit ids to be merged\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '24']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '24', 'type': 'block', 'children': ['25', '35']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_id'},{'id': '28', 'type': 'attribute', 'children': ['29', '34']},{'id': '29', 'type': 'subscript', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'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': 'root_ids'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'root_id'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'indices_to_be_deleted'},{'id': '45', 'type': 'list', 'children': [], 'value': '[]'},{'id': '46', 'type': 'if_statement', 'children': ['47', '67', '364']},{'id': '47', 'type': '()', 'children': ['48']},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '61'], 'value': 'and'},{'id': '49', 'type': 'call', 'children': ['50', '56']},{'id': '50', 'type': 'attribute', 'children': ['51', '55']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '66'], 'value': '>'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'block', 'children': ['68', '72', '92', '101', '116', '123', '127', '144', '155', '164', '171', '175', '271', '280', '289', '303', '305', '328', '337']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'all_feature_names'},{'id': '71', 'type': 'list', 'children': [], 'value': '[]'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '75', 'type': 'block', 'children': ['76', '85']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'feature_names'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_feature_names'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'all_feature_names'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'feature_names'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'all_feature_names'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '108']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'feature_names'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'all_feature_names'},{'id': '105', 'type': 'slice', 'children': ['106', '107']},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'colon', 'children': []},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'intersection_update'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'feature_names'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'shared_features'},{'id': '126', 'type': 'list', 'children': [], 'value': '[]'},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '136']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '136', 'type': 'block', 'children': ['137']},{'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': 'shared_features'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'list', 'children': [], 'value': '[]'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'new_root_id'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '154'], 'value': '+'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '154', 'type': 'integer', 'children': [], 'value': '1'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'new_root_id'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'new_root'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Unit'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'new_root_id'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'id': '174', 'type': 'list', 'children': [], 'value': '[]'},{'id': '175', 'type': 'for_statement', 'children': ['176', '177', '178']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '178', 'type': 'block', 'children': ['179', '188', '199', '214', '242', '248', '264']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'new_root'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'add_child'},{'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': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'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': 'all_spike_trains'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '213']},{'id': '206', 'type': 'attribute', 'children': ['207', '212']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'get_spike_train'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'for_statement', 'children': ['215', '218', '222']},{'id': '215', 'type': 'pattern_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '222', 'type': 'block', 'children': ['223', '233']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_features'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'shared_features'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '242', 'type': 'delete_statement', 'children': ['243']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': '_unit_features'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '257']},{'id': '250', 'type': 'attribute', 'children': ['251', '256']},{'id': '251', 'type': 'subscript', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'set_spike_train'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'indices_to_be_deleted'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'sort_indices'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'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': 'new_root'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'set_spike_train'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'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': 'np'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'sort_indices'},{'id': '303', 'type': 'delete_statement', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'all_spike_trains'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '309', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '310', 'type': 'list_comprehension', 'children': ['311', '316', '324']},{'id': '311', 'type': 'subscript', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '314', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '316', 'type': 'for_in_clause', 'children': ['317', '320']},{'id': '317', 'type': 'pattern_list', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '319', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '324', 'type': 'if_clause', 'children': ['325']},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': 'not'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'indices_to_be_deleted'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '335']},{'id': '330', 'type': 'attribute', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'new_root'},{'id': '337', 'type': 'for_statement', 'children': ['338', '341', '345']},{'id': '338', 'type': 'pattern_list', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'shared_feature_names'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'set_unit_spike_features'},{'id': '351', 'type': 'argument_list', 'children': ['352', '353', '354']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'new_root_id'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '354', 'type': 'subscript', 'children': ['355', '363']},{'id': '355', 'type': 'call', 'children': ['356', '359']},{'id': '356', 'type': 'attribute', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'subscript', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'shared_features'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'sort_indices'},{'id': '364', 'type': 'else_clause', 'children': ['365']},{'id': '365', 'type': 'block', 'children': ['366']},{'id': '366', 'type': 'raise_statement', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'binary_operator', 'children': ['371', '375'], 'value': '+'},{'id': '371', 'type': 'call', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '373', 'type': 'argument_list', 'children': ['374']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'unit_ids'},{'id': '375', 'type': 'string', 'children': [], 'value': '" has one or more invalid unit ids"'} | def merge_units(self, unit_ids):
'''This function merges two roots from the curation tree according to the given unit_ids. It creates a new unit_id and root
that has the merged roots as children.
Parameters
----------
unit_ids: list
The unit ids to be merged
'''
root_ids = []
for i in range(len(self._roots)):
root_id = self._roots[i].unit_id
root_ids.append(root_id)
indices_to_be_deleted = []
if(set(unit_ids).issubset(set(root_ids)) and len(unit_ids) > 1):
all_feature_names = []
for unit_id in unit_ids:
feature_names = self.get_unit_spike_feature_names(unit_id)
all_feature_names.append(feature_names)
shared_feature_names = set(all_feature_names[0])
for feature_names in all_feature_names[1:]:
shared_feature_names.intersection_update(feature_names)
shared_feature_names = list(shared_feature_names)
shared_features = []
for i in range(len(shared_feature_names)):
shared_features.append([])
new_root_id = max(self._all_ids)+1
self._all_ids.append(new_root_id)
new_root = Unit(new_root_id)
all_spike_trains = []
for unit_id in unit_ids:
root_index = root_ids.index(unit_id)
new_root.add_child(self._roots[root_index])
all_spike_trains.append(self._roots[root_index].get_spike_train())
for i, feature_name in enumerate(shared_feature_names):
features = self.get_unit_spike_features(unit_id, feature_name)
shared_features[i].append(features)
del self._unit_features[unit_id]
self._roots[root_index].set_spike_train(np.asarray([]))
indices_to_be_deleted.append(root_index)
all_spike_trains = np.concatenate(all_spike_trains)
sort_indices = np.argsort(all_spike_trains)
new_root.set_spike_train(np.asarray(all_spike_trains)[sort_indices])
del all_spike_trains
self._roots = [self._roots[i] for i,_ in enumerate(root_ids) if i not in indices_to_be_deleted]
self._roots.append(new_root)
for i, feature_name in enumerate(shared_feature_names):
self.set_unit_spike_features(new_root_id, feature_name, np.concatenate(shared_features[i])[sort_indices])
else:
raise ValueError(str(unit_ids) + " has one or more invalid unit ids") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_unit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '7', 'type': 'block', 'children': ['8', '10', '14', '43']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''This function splits a root from the curation tree according to the given unit_id and indices. It creates two new unit_ids\n and roots that have the split root as a child. This function splits the spike train of the root by the given indices.\n Parameters\n ----------\n unit_id: int\n The unit id to be split\n indices: list\n The indices of the unit spike train at which the spike train will be split.\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '25']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '25', 'type': 'block', 'children': ['26', '36']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'root_id'},{'id': '29', 'type': 'attribute', 'children': ['30', '35']},{'id': '30', 'type': 'subscript', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'root_id'},{'id': '43', 'type': 'if_statement', 'children': ['44', '48', '306']},{'id': '44', 'type': '()', 'children': ['45']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '48', 'type': 'block', 'children': ['49', '69', '78', '86', '98', '124', '145', '151', '153', '164', '173', '180', '187', '194', '205', '214', '221', '228', '235', '244', '253', '294', '300']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'indices_1'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'root_ids'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_child'},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'original_spike_train'},{'id': '89', 'type': 'call', 'children': ['90', '97']},{'id': '90', 'type': 'attribute', 'children': ['91', '96']},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'get_spike_train'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'try_statement', 'children': ['99', '106']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'spike_train_1'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'original_spike_train'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'indices_1'},{'id': '106', 'type': 'except_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '108', 'type': 'block', 'children': ['109']},{'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': 'binary_operator', 'children': ['114', '120'], 'value': '+'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '119'], 'value': '+'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '119', 'type': 'string', 'children': [], 'value': '" out of bounds for the spike train of "'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'indices_2'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'binary_operator', 'children': ['131', '141'], 'value': '-'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'original_spike_train'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'indices_1'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'spike_train_2'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'original_spike_train'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'indices_2'},{'id': '151', 'type': 'delete_statement', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'original_spike_train'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'new_root_1_id'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '163'], 'value': '+'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '163', 'type': 'integer', 'children': [], 'value': '1'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_root_1_id'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'new_root_1'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Unit'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'new_root_1_id'},{'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': 'new_root_1'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'add_child'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'new_child'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'new_root_1'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'set_spike_train'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'spike_train_1'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'new_root_2_id'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '204'], 'value': '+'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'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': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_all_ids'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_root_2_id'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'new_root_2'},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'Unit'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'new_root_2_id'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'new_root_2'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'add_child'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'new_child'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'new_root_2'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'set_spike_train'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'spike_train_2'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'new_root_1'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '251']},{'id': '246', 'type': 'attribute', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '249', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'new_root_2'},{'id': '253', 'type': 'for_statement', 'children': ['254', '255', '261']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_feature_names'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '261', 'type': 'block', 'children': ['262', '272', '283']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'full_features'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'get_unit_spike_features'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'set_unit_spike_features'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'new_root_1_id'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'full_features'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'indices_1'},{'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': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'set_unit_spike_features'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'new_root_2_id'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'feature_name'},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'full_features'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'indices_2'},{'id': '294', 'type': 'delete_statement', 'children': ['295']},{'id': '295', 'type': 'subscript', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': '_unit_features'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '300', 'type': 'delete_statement', 'children': ['301']},{'id': '301', 'type': 'subscript', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '304', 'type': 'identifier', 'children': [], 'value': '_roots'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'root_index'},{'id': '306', 'type': 'else_clause', 'children': ['307']},{'id': '307', 'type': 'block', 'children': ['308']},{'id': '308', 'type': 'raise_statement', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'binary_operator', 'children': ['313', '317'], 'value': '+'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'unit_id'},{'id': '317', 'type': 'string', 'children': [], 'value': '" non-valid unit id"'} | def split_unit(self, unit_id, indices):
'''This function splits a root from the curation tree according to the given unit_id and indices. It creates two new unit_ids
and roots that have the split root as a child. This function splits the spike train of the root by the given indices.
Parameters
----------
unit_id: int
The unit id to be split
indices: list
The indices of the unit spike train at which the spike train will be split.
'''
root_ids = []
for i in range(len(self._roots)):
root_id = self._roots[i].unit_id
root_ids.append(root_id)
if(unit_id in root_ids):
indices_1 = np.sort(np.asarray(list(set(indices))))
root_index = root_ids.index(unit_id)
new_child = self._roots[root_index]
original_spike_train = self._roots[root_index].get_spike_train()
try:
spike_train_1 = original_spike_train[indices_1]
except IndexError:
print(str(indices) + " out of bounds for the spike train of " + str(unit_id))
indices_2 = list(set(range(len(original_spike_train))) - set(indices_1))
spike_train_2 = original_spike_train[indices_2]
del original_spike_train
new_root_1_id = max(self._all_ids)+1
self._all_ids.append(new_root_1_id)
new_root_1 = Unit(new_root_1_id)
new_root_1.add_child(new_child)
new_root_1.set_spike_train(spike_train_1)
new_root_2_id = max(self._all_ids)+1
self._all_ids.append(new_root_2_id)
new_root_2 = Unit(new_root_2_id)
new_root_2.add_child(new_child)
new_root_2.set_spike_train(spike_train_2)
self._roots.append(new_root_1)
self._roots.append(new_root_2)
for feature_name in self.get_unit_spike_feature_names(unit_id):
full_features = self.get_unit_spike_features(unit_id, feature_name)
self.set_unit_spike_features(new_root_1_id, feature_name, full_features[indices_1])
self.set_unit_spike_features(new_root_2_id, feature_name, full_features[indices_2])
del self._unit_features[unit_id]
del self._roots[root_index]
else:
raise ValueError(str(unit_id) + " non-valid unit id") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_best_fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pbin'},{'id': '6', 'type': 'block', 'children': ['7', '35', '49']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '10', 'type': 'generator_expression', 'children': ['11', '24']},{'id': '11', 'type': 'tuple', 'children': ['12', '23']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pbin'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fitness'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20']},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '28']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_sorted_rect'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '38', 'type': 'generator_expression', 'children': ['39', '40', '43']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '43', 'type': 'if_clause', 'children': ['44']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'is'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'try_statement', 'children': ['50', '67']},{'id': '50', 'type': 'block', 'children': ['51', '65']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'first_item'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'rect'},{'id': '67', 'type': 'except_clause', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'None', 'children': []} | def _find_best_fit(self, pbin):
fit = ((pbin.fitness(r[0], r[1]), k) for k, r in self._sorted_rect.items())
fit = (f for f in fit if f[0] is not None)
try:
_, rect = min(fit, key=self.first_item)
return rect
except ValueError:
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_item_attributes_match'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'crypto_config'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'plaintext_item'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'encrypted_item'},{'id': '7', 'type': 'block', 'children': ['8', '45']},{'id': '8', 'type': 'for_statement', 'children': ['9', '12', '17']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'plaintext_item'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '33']},{'id': '18', 'type': 'if_statement', 'children': ['19', '31']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '28'], 'value': '=='},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'crypto_config'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'attribute_actions'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'CryptoAction'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ENCRYPT_AND_SIGN'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'continue_statement', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '42']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '41'], 'value': '!='},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'encrypted_item'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'True', 'children': []} | def _item_attributes_match(crypto_config, plaintext_item, encrypted_item):
for name, value in plaintext_item.items():
if crypto_config.attribute_actions.action(name) == CryptoAction.ENCRYPT_AND_SIGN:
continue
if encrypted_item.get(name) != value:
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_css'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '25', '36', '45', '181', '187', '231', '253']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'icons'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'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': 'parser'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tinycss'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'make_parser'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'page3'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'stylesheet'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parse_stylesheet_file'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'css_file'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'is_icon'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '"\\.(.*):before,?"'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stylesheet'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'rules'},{'id': '50', 'type': 'block', 'children': ['51', '61', '71', '103']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'as_css'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'if_statement', 'children': ['62', '69']},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'is_icon'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'continue_statement', 'children': []},{'id': '71', 'type': 'if_statement', 'children': ['72', '75', '84']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '74', 'type': 'None', 'children': []},{'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': 'common_prefix'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '81', 'type': 'slice', 'children': ['82', '83']},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'colon', 'children': []},{'id': '84', 'type': 'else_clause', 'children': ['85']},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'commonprefix'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'tuple', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '100', 'type': 'slice', 'children': ['101', '102']},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'colon', 'children': []},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '111']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'is_icon'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'selector'},{'id': '111', 'type': 'block', 'children': ['112', '122']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'subscript', 'children': ['116', '121']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '127']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'declaration'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rule'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '134']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'declaration'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '133', 'type': 'string', 'children': [], 'value': '"content"'},{'id': '134', 'type': 'block', 'children': ['135', '145', '164']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'val'},{'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': 'declaration'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'as_css'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'if_statement', 'children': ['146', '153']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"^[\'\\"].*[\'\\"]$"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '159', 'type': 'slice', 'children': ['160', '161', '162']},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'colon', 'children': []},{'id': '162', 'type': 'unary_operator', 'children': ['163'], 'value': '-'},{'id': '163', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'icons'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'unichr'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '174', 'type': 'argument_list', 'children': ['175', '180']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '177', 'type': 'slice', 'children': ['178', '179']},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'colon', 'children': []},{'id': '180', 'type': 'integer', 'children': [], 'value': '16'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '186'], 'value': 'or'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '186', 'type': 'string', 'children': [], 'value': "''"},{'id': '187', 'type': 'if_statement', 'children': ['188', '199']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '193'], 'value': 'and'},{'id': '189', 'type': 'not_operator', 'children': ['190']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'keep_prefix'},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '198'], 'value': '>'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'common_prefix'},{'id': '198', 'type': 'integer', 'children': [], 'value': '0'},{'id': '199', 'type': 'block', 'children': ['200', '204', '227']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'non_prefixed_icons'},{'id': '203', 'type': 'dictionary', 'children': []},{'id': '204', 'type': 'for_statement', 'children': ['205', '206', '211']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'icons'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '224']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'non_prefixed_icons'},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '218', 'type': 'slice', 'children': ['219', '223']},{'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': 'common_prefix'},{'id': '223', 'type': 'colon', 'children': []},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'icons'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'icons'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'non_prefixed_icons'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'sorted_icons'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '239', 'type': 'argument_list', 'children': ['240', '245']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'icons'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '247', 'type': 'lambda', 'children': ['248', '250']},{'id': '248', 'type': 'lambda_parameters', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'return_statement', 'children': ['254']},{'id': '254', 'type': 'expression_list', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sorted_icons'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'common_prefix'} | def load_css(self):
icons = dict()
common_prefix = None
parser = tinycss.make_parser('page3')
stylesheet = parser.parse_stylesheet_file(self.css_file)
is_icon = re.compile("\.(.*):before,?")
for rule in stylesheet.rules:
selector = rule.selector.as_css()
if not is_icon.match(selector):
continue
if common_prefix is None:
common_prefix = selector[1:]
else:
common_prefix = os.path.commonprefix((common_prefix,
selector[1:]))
for match in is_icon.finditer(selector):
name = match.groups()[0]
for declaration in rule.declarations:
if declaration.name == "content":
val = declaration.value.as_css()
if re.match("^['\"].*['\"]$", val):
val = val[1:-1]
icons[name] = unichr(int(val[1:], 16))
common_prefix = common_prefix or ''
if not self.keep_prefix and len(common_prefix) > 0:
non_prefixed_icons = {}
for name in icons.keys():
non_prefixed_icons[name[len(common_prefix):]] = icons[name]
icons = non_prefixed_icons
sorted_icons = OrderedDict(sorted(icons.items(), key=lambda t: t[0]))
return sorted_icons, common_prefix |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rules'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '252', '325']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'list_of_rules'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '15']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict_rules'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '228']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'},{'id': '18', 'type': 'string', 'children': [], 'value': "'rules'"},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '26']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '25', 'type': 'string', 'children': [], 'value': "'rules'"},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '184']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'},{'id': '29', 'type': 'string', 'children': [], 'value': "'grants'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '37']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '36', 'type': 'string', 'children': [], 'value': "'grants'"},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42', '119', '176']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'},{'id': '40', 'type': 'string', 'children': [], 'value': "'group_id'"},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '42', 'type': 'block', 'children': ['43', '49', '66', '112']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '48', 'type': 'string', 'children': [], 'value': "'group_id'"},{'id': '49', 'type': 'if_statement', 'children': ['50', '53', '60']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'},{'id': '51', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'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': 'row_name'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '59', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'row_name'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'FirewallRule'},{'id': '71', 'type': 'argument_list', 'children': ['72', '75', '78', '81', '86', '91', '96', '101', '104', '107']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '74', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '77', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '80', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'rules_direction'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '85', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'rules_ip_protocol'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '90', 'type': 'string', 'children': [], 'value': "'ip_protocol'"},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'rules_from_port'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '95', 'type': 'string', 'children': [], 'value': "'from_port'"},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'rules_to_port'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '100', 'type': 'string', 'children': [], 'value': "'to_port'"},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'rules_grants_group_id'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'rules_grants_name'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'row_name'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'rules_description'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '111', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'list_of_rules'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '119', 'type': 'elif_clause', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'in'},{'id': '121', 'type': 'string', 'children': [], 'value': "'cidr_ip'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '123', 'type': 'block', 'children': ['124', '169']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'FirewallRule'},{'id': '129', 'type': 'argument_list', 'children': ['130', '133', '136', '139', '144', '149', '154', '159', '164']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '132', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '135', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '138', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'rules_direction'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '143', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'rules_ip_protocol'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '148', 'type': 'string', 'children': [], 'value': "'ip_protocol'"},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'rules_from_port'},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '153', 'type': 'string', 'children': [], 'value': "'from_port'"},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'rules_to_port'},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '158', 'type': 'string', 'children': [], 'value': "'to_port'"},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'rules_grants_cidr_ip'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '163', 'type': 'string', 'children': [], 'value': "'cidr_ip'"},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'rules_description'},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '168', 'type': 'string', 'children': [], 'value': "'description'"},{'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': 'list_of_rules'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'raise_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': '"Unsupported grant:"'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'grant_row'},{'id': '184', 'type': 'else_clause', 'children': ['185']},{'id': '185', 'type': 'block', 'children': ['186', '221']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'FirewallRule'},{'id': '191', 'type': 'argument_list', 'children': ['192', '195', '198', '201', '206', '211', '216']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '194', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '197', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '200', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'rules_direction'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '205', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'rules_ip_protocol'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '210', 'type': 'string', 'children': [], 'value': "'ip_protocol'"},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rules_from_port'},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '215', 'type': 'string', 'children': [], 'value': "'from_port'"},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'rules_to_port'},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'rule_row'},{'id': '220', 'type': 'string', 'children': [], 'value': "'to_port'"},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'list_of_rules'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '228', 'type': 'else_clause', 'children': ['229']},{'id': '229', 'type': 'block', 'children': ['230', '245']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'FirewallRule'},{'id': '235', 'type': 'argument_list', 'children': ['236', '239', '242']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '238', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '241', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'main_row'},{'id': '244', 'type': 'string', 'children': [], 'value': "'description'"},{'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': 'list_of_rules'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'list_of_rules'},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '261', 'type': 'lambda', 'children': ['262', '264']},{'id': '262', 'type': 'lambda_parameters', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '264', 'type': 'tuple', 'children': ['265', '271', '277', '283', '289', '295', '301', '307', '313', '319']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'rules_direction'},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'rules_ip_protocol'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'rules_from_port'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'rules_to_port'},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'rules_grants_group_id'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'rules_grants_name'},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'fr'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'rules_grants_cidr_ip'},{'id': '325', 'type': 'return_statement', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'sorted_list'} | def rules(self):
list_of_rules = []
for main_row in self.dict_rules:
if 'rules' in main_row:
for rule_row in main_row['rules']:
if 'grants' in rule_row:
for grant_row in rule_row['grants']:
if 'group_id' in grant_row:
group_id = grant_row['group_id']
if 'name' in grant_row:
row_name = grant_row['name']
else:
row_name = None
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'],
rules_grants_group_id=group_id,
rules_grants_name=row_name,
rules_description=grant_row['description'])
list_of_rules.append(fr)
elif 'cidr_ip' in grant_row:
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'],
rules_grants_cidr_ip=grant_row['cidr_ip'],
rules_description=grant_row['description'])
list_of_rules.append(fr)
else:
raise ValueError("Unsupported grant:",
grant_row)
else:
fr = FirewallRule(
main_row['id'],
main_row['name'],
main_row['description'],
rules_direction=rule_row['direction'],
rules_ip_protocol=rule_row['ip_protocol'],
rules_from_port=rule_row['from_port'],
rules_to_port=rule_row['to_port'])
list_of_rules.append(fr)
else:
fr = FirewallRule(main_row['id'],
main_row['name'],
main_row['description'])
list_of_rules.append(fr)
sorted_list = sorted(list_of_rules,
key=lambda fr: (str(fr.id),
str(fr.name),
str(fr.description),
str(fr.rules_direction),
str(fr.rules_ip_protocol),
str(fr.rules_from_port),
str(fr.rules_to_port),
str(fr.rules_grants_group_id),
str(fr.rules_grants_name),
str(fr.rules_grants_cidr_ip)))
return sorted_list |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_select_mgmt_networks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '6', 'type': 'block', 'children': ['7', '13', '39', '84', '109']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '10', 'type': 'subscript', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '12', 'type': 'string', 'children': [], 'value': "'nets'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'mgmts'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '21', '30']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '25']},{'id': '22', 'type': 'pattern_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'net'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'if_clause', 'children': ['31']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '38'], 'value': 'is'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'net'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'management'"},{'id': '38', 'type': 'True', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '46']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '45'], 'value': '=='},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mgmts'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'block', 'children': ['47', '61', '69', '77']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '50', 'type': 'subscript', 'children': ['51', '60']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': '()', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'No management network configured, selecting network %s'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '76']},{'id': '71', 'type': 'subscript', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '75', 'type': 'string', 'children': [], 'value': "'management'"},{'id': '76', 'type': 'True', 'children': []},{'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': 'mgmts'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'mgmts'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '100']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '99'], 'value': 'is'},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': "'dns_domain_name'"},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'None', 'children': []},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '108']},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'nets'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mgmt_name'},{'id': '107', 'type': 'string', 'children': [], 'value': "'dns_domain_name'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'lago.local'"},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'mgmts'} | def _select_mgmt_networks(self, conf):
nets = conf['nets']
mgmts = sorted(
[
name for name, net in nets.iteritems()
if net.get('management') is True
]
)
if len(mgmts) == 0:
mgmt_name = sorted((nets.keys()))[0]
LOGGER.debug(
'No management network configured, selecting network %s',
mgmt_name
)
nets[mgmt_name]['management'] = True
mgmts.append(mgmt_name)
for mgmt_name in mgmts:
if nets[mgmt_name].get('dns_domain_name', None) is None:
nets[mgmt_name]['dns_domain_name'] = 'lago.local'
return mgmts |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_wavetable'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '45', '54', '107', '122']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_wavetable'},{'id': '12', 'type': 'if_statement', 'children': ['13', '21']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '<='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'block', 'children': ['22', '35']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'wrong'},{'id': '25', 'type': 'subscript', 'children': ['26', '34']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '<='},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ZeroWavelength'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'Negative or Zero wavelength occurs in wavelength array'"},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'wrong'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '54', 'type': 'if_statement', 'children': ['55', '64']},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'alltrue'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '=='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '80', '82']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'alltrue'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '79'], 'value': '=='},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '74', 'type': 'slice', 'children': ['75', '76', '77']},{'id': '75', 'type': 'colon', 'children': []},{'id': '76', 'type': 'colon', 'children': []},{'id': '77', 'type': 'unary_operator', 'children': ['78'], 'value': '-'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'pass_statement', 'children': []},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '97']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'wrong'},{'id': '87', 'type': 'subscript', 'children': ['88', '96']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '!='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'wave'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'UnsortedWavelength'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'Wavelength array is not monotonic'"},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'wrong'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '116'], 'value': '-'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '113', 'type': 'slice', 'children': ['114', '115']},{'id': '114', 'type': 'integer', 'children': [], 'value': '1'},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '118', 'type': 'slice', 'children': ['119', '120']},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'if_statement', 'children': ['123', '131']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'block', 'children': ['132', '145']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'wrong'},{'id': '135', 'type': 'subscript', 'children': ['136', '144']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dw'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'raise_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'DuplicateWavelength'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"Wavelength array contains duplicate entries"'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'wrong'} | def validate_wavetable(self):
wave = self._wavetable
if N.any(wave <= 0):
wrong = N.where(wave <= 0)[0]
raise exceptions.ZeroWavelength(
'Negative or Zero wavelength occurs in wavelength array',
rows=wrong)
sorted = N.sort(wave)
if not N.alltrue(sorted == wave):
if N.alltrue(sorted[::-1] == wave):
pass
else:
wrong = N.where(sorted != wave)[0]
raise exceptions.UnsortedWavelength(
'Wavelength array is not monotonic', rows=wrong)
dw = sorted[1:] - sorted[:-1]
if N.any(dw == 0):
wrong = N.where(dw == 0)[0]
raise exceptions.DuplicateWavelength(
"Wavelength array contains duplicate entries", rows=wrong) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getStateIndex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '6', 'type': 'block', 'children': ['7', '16']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'statecodes'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'getStateCode'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '29']},{'id': '18', 'type': 'attribute', 'children': ['19', '28']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'statecodes'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'int'} | def getStateIndex(self,state):
statecodes = self.getStateCode(state)
return np.searchsorted(self.codes,statecodes).astype(int) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'guess_chimera_path'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '6', 'type': 'False', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '20', '55', '71']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_search_chimera'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '16', '17']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_BINARY'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_LOCATIONS'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_PREFIX'},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '20', 'type': 'if_statement', 'children': ['21', '25']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '24'], 'value': 'and'},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '25', 'type': 'block', 'children': ['26', '43']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'{0[0]}{1}{0[1]}'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '33', 'type': 'argument_list', 'children': ['34', '42']},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_BINARY'},{'id': '42', 'type': 'string', 'children': [], 'value': "'-headless'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_search_chimera'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51', '52']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'headless'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_LOCATIONS'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'CHIMERA_PREFIX'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'search_all'},{'id': '55', 'type': 'if_statement', 'children': ['56', '58']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '58', 'type': 'block', 'children': ['59']},{'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': 'sys'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': '"Could not find UCSF Chimera.\\n{}"'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_INSTRUCTIONS'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'paths'} | def guess_chimera_path(search_all=False):
paths = _search_chimera(CHIMERA_BINARY, CHIMERA_LOCATIONS, CHIMERA_PREFIX,
search_all=search_all)
if not paths and search_all:
headless = '{0[0]}{1}{0[1]}'.format(os.path.split(CHIMERA_BINARY), '-headless')
paths = _search_chimera(headless, CHIMERA_LOCATIONS, CHIMERA_PREFIX,
search_all=search_all)
if not paths:
sys.exit("Could not find UCSF Chimera.\n{}".format(_INSTRUCTIONS))
return paths |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_topo_sort'},{'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': 'forward'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '19', '23', '64', '97', '154', '179']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'topo_list'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'deque'},{'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': 'indeg'},{'id': '22', 'type': 'dictionary', 'children': []},{'id': '23', 'type': 'if_statement', 'children': ['24', '25', '44']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'forward'},{'id': '25', 'type': 'block', 'children': ['26', '32', '38']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_edges'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'out_edges'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_degree'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'inc_degree'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'get_next'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '44', 'type': 'else_clause', 'children': ['45']},{'id': '45', 'type': 'block', 'children': ['46', '52', '58']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_edges'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'inc_edges'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_degree'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'out_degree'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_next'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '71']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'node'},{'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': 'node_list'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'block', 'children': ['72', '79']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'degree'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get_degree'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '79', 'type': 'if_statement', 'children': ['80', '81', '88']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'degree'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'indeg'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'degree'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'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': 'queue'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '97', 'type': 'while_statement', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '99', 'type': 'block', 'children': ['100', '108', '115']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'curr_node'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '107', 'type': 'argument_list', 'children': []},{'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': 'topo_list'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'curr_node'},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '121']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'get_edges'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'curr_node'},{'id': '121', 'type': 'block', 'children': ['122', '129']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'tail_id'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_next'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '129', 'type': 'if_statement', 'children': ['130', '133']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'tail_id'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'indeg'},{'id': '133', 'type': 'block', 'children': ['134', '140']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'augmented_assignment', 'children': ['136', '139'], 'value': '-='},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'indeg'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tail_id'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'if_statement', 'children': ['141', '146']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': '=='},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'indeg'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tail_id'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tail_id'},{'id': '154', 'type': 'if_statement', 'children': ['155', '168', '173']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '160'], 'value': '=='},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'topo_list'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '162', 'type': 'argument_list', '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': 'node_list'},{'id': '167', 'type': 'argument_list', 'children': []},{'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': 'valid'},{'id': '172', 'type': 'True', 'children': []},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '178', 'type': 'False', 'children': []},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'tuple', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'topo_list'} | def _topo_sort(self, forward=True):
topo_list = []
queue = deque()
indeg = {}
if forward:
get_edges = self.out_edges
get_degree = self.inc_degree
get_next = self.tail
else:
get_edges = self.inc_edges
get_degree = self.out_degree
get_next = self.head
for node in self.node_list():
degree = get_degree(node)
if degree:
indeg[node] = degree
else:
queue.append(node)
while queue:
curr_node = queue.popleft()
topo_list.append(curr_node)
for edge in get_edges(curr_node):
tail_id = get_next(edge)
if tail_id in indeg:
indeg[tail_id] -= 1
if indeg[tail_id] == 0:
queue.append(tail_id)
if len(topo_list) == len(self.node_list()):
valid = True
else:
valid = False
return (valid, topo_list) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute_sql'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'server_context'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schema_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'container_path'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'max_rows'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'container_filter'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'save_in_session'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'required_version'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_default_timeout'},{'id': '34', 'type': 'block', 'children': ['35', '48', '58', '69', '80', '91', '102', '113', '136', '147']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'server_context'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'build_url'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']},{'id': '43', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'executeSql.api'"},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'container_path'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'container_path'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '51', 'type': 'dictionary', 'children': ['52', '55']},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'schemaName'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'schema_name'},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "'sql'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'container_filter'},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '67', 'type': 'string', 'children': [], 'value': "'containerFilter'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'container_filter'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'max_rows'},{'id': '72', 'type': 'None', 'children': []},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '78', 'type': 'string', 'children': [], 'value': "'maxRows'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'max_rows'},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'is'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '90']},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '89', 'type': 'string', 'children': [], 'value': "'offset'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '100', 'type': 'string', 'children': [], 'value': "'query.sort'"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'save_in_session'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '111', 'type': 'string', 'children': [], 'value': "'saveInSession'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'save_in_session'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'is'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '116', 'type': 'None', 'children': []},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'for_statement', 'children': ['119', '122', '127']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '135']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'},{'id': '133', 'type': 'string', 'children': [], 'value': "'query.param.'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'required_version'},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '145', 'type': 'string', 'children': [], 'value': "'apiVersion'"},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'required_version'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'server_context'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'make_request'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'timeout'} | def execute_sql(server_context, schema_name, sql, container_path=None,
max_rows=None,
sort=None,
offset=None,
container_filter=None,
save_in_session=None,
parameters=None,
required_version=None,
timeout=_default_timeout):
url = server_context.build_url('query', 'executeSql.api', container_path=container_path)
payload = {
'schemaName': schema_name,
'sql': sql
}
if container_filter is not None:
payload['containerFilter'] = container_filter
if max_rows is not None:
payload['maxRows'] = max_rows
if offset is not None:
payload['offset'] = offset
if sort is not None:
payload['query.sort'] = sort
if save_in_session is not None:
payload['saveInSession'] = save_in_session
if parameters is not None:
for key, value in parameters.items():
payload['query.param.' + key] = value
if required_version is not None:
payload['apiVersion'] = required_version
return server_context.make_request(url, payload, timeout=timeout) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_missing_projections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'label_list'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'projections'},{'id': '6', 'type': 'block', 'children': ['7', '13', '20', '58']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'unmapped_combinations'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'WILDCARD_COMBINATION'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'projections'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '27']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'labeled_segment'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'label_list'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ranges'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '46']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'combination'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'list_comprehension', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'labeled_segment'},{'id': '45', 'type': 'integer', 'children': [], 'value': '2'},{'id': '46', 'type': 'if_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'combination'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'projections'},{'id': '50', 'type': 'block', 'children': ['51']},{'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': 'unmapped_combinations'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'combination'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'unmapped_combinations'} | def find_missing_projections(label_list, projections):
unmapped_combinations = set()
if WILDCARD_COMBINATION in projections:
return []
for labeled_segment in label_list.ranges():
combination = tuple(sorted([label.value for label in labeled_segment[2]]))
if combination not in projections:
unmapped_combinations.add(combination)
return sorted(unmapped_combinations) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_projections'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'projections_file'},{'id': '5', 'type': 'block', 'children': ['6', '10', '61']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'projections'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '19']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'textfile'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'read_separated_lines_generator'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'projections_file'},{'id': '18', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '19', 'type': 'block', 'children': ['20', '45', '55']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'combination'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '35']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "' '"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'new_label'},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '54', 'type': 'argument_list', 'children': []},{'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': 'projections'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'combination'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'new_label'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'projections'} | def load_projections(projections_file):
projections = {}
for parts in textfile.read_separated_lines_generator(projections_file, '|'):
combination = tuple(sorted([label.strip() for label in parts[0].split(' ')]))
new_label = parts[1].strip()
projections[combination] = new_label
return projections |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'label_values'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_labels'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'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': 'all_labels'} | def label_values(self):
all_labels = set([l.value for l in self])
return sorted(all_labels) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_utt_regions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '129']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'regions'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'current_offset'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '22']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'utt_idx'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'utt_ids'},{'id': '22', 'type': 'block', 'children': ['23', '27', '31', '35', '72', '93', '111', '118', '125']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'current_offset'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'num_frames'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '40', 'type': 'block', 'children': ['41', '57']},{'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': 'num_frames'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'subscript', 'children': ['48', '56']},{'id': '48', 'type': 'attribute', 'children': ['49', '55']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'utt_idx'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'refs'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'utt_idx'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'mem_map'},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'if_statement', 'children': ['73', '82']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '81'], 'value': '!='},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'num_frames'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'Utterance {} has not the same number of frames in all containers!'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'utt_idx'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'num_chunks'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '/'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'num_frames'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'frames_per_chunk'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '114', 'type': 'tuple', 'children': ['115', '116', '117']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'num_chunks'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'refs'},{'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': 'regions'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'current_offset'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'num_chunks'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'regions'} | def get_utt_regions(self):
regions = []
current_offset = 0
for utt_idx in sorted(self.utt_ids):
offset = current_offset
num_frames = []
refs = []
for cnt in self.containers:
num_frames.append(cnt.get(utt_idx).shape[0])
refs.append(cnt.get(utt_idx, mem_map=True))
if len(set(num_frames)) != 1:
raise ValueError('Utterance {} has not the same number of frames in all containers!'.format(utt_idx))
num_chunks = math.ceil(num_frames[0] / float(self.frames_per_chunk))
region = (offset, num_chunks, refs)
regions.append(region)
current_offset += num_chunks
return regions |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_separated_lines'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '8', 'type': 'string', 'children': [], 'value': "' '"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_by_column'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'block', 'children': ['13', '24', '183']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '20', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '23', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '24', 'type': 'if_statement', 'children': ['25', '31', '114']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': 'is'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '31', 'type': 'block', 'children': ['32', '68']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '58']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort_by_column'},{'id': '35', 'type': 'list', 'children': ['36', '37'], 'value': '[0, 1]'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '44', 'type': 'argument_list', 'children': ['45', '50']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'lambda', 'children': ['53', '55']},{'id': '53', 'type': 'lambda_parameters', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort_by_column'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '72', '73']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '73', 'type': 'block', 'children': ['74', '100']},{'id': '74', 'type': 'if_statement', 'children': ['75', '83']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': 'in'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'list', 'children': ['81', '82'], 'value': '[list, set]'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'value'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'list_comprehension', 'children': ['93', '97']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'},{'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': 'f'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'{}{}{}\\n'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '114', 'type': 'elif_clause', 'children': ['115', '128']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '122'], 'value': 'or'},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '121'], 'value': 'is'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '127'], 'value': 'is'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '128', 'type': 'block', 'children': ['129', '151']},{'id': '129', 'type': 'if_statement', 'children': ['130', '137', '145']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132', '133'], 'value': '<='},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sort_by_column'},{'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': 'values'},{'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': 'items'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'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': 'items'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '154', 'type': 'block', 'children': ['155', '166']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'str_values'},{'id': '158', 'type': 'list_comprehension', 'children': ['159', '163']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '163', 'type': 'for_in_clause', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': "'{}\\n'"},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'str_values'},{'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': 'f'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '188', 'type': 'argument_list', 'children': []} | def write_separated_lines(path, values, separator=' ', sort_by_column=0):
f = open(path, 'w', encoding='utf-8')
if type(values) is dict:
if sort_by_column in [0, 1]:
items = sorted(values.items(), key=lambda t: t[sort_by_column])
else:
items = values.items()
for key, value in items:
if type(value) in [list, set]:
value = separator.join([str(x) for x in value])
f.write('{}{}{}\n'.format(key, separator, value))
elif type(values) is list or type(values) is set:
if 0 <= sort_by_column < len(values):
items = sorted(values)
else:
items = values
for record in items:
str_values = [str(value) for value in record]
f.write('{}\n'.format(separator.join(str_values)))
f.close() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_set'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '5', 'type': 'block', 'children': ['6', '19', '26', '43']},{'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': 's'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Set'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': '"sets only"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'frozenset'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'not'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_sort_set_memo'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_sort_set_memo'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_sort_set_key'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_sort_set_memo'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 's'} | def sort_set(s):
if not isinstance(s, Set):
raise TypeError("sets only")
s = frozenset(s)
if s not in _sort_set_memo:
_sort_set_memo[s] = sorted(s, key=_sort_set_key)
return _sort_set_memo[s] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_tags'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tagstring'},{'id': '5', 'type': 'block', 'children': ['6', '12', '19', '23', '27', '31', '38', '163', '185', '195', '201']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tagstring'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'tagstring'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'force_text'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tagstring'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '26', 'type': 'list', 'children': [], 'value': '[]'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'to_be_split'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tagstring'},{'id': '38', 'type': 'try_statement', 'children': ['39', '145']},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'while_statement', 'children': ['41', '42']},{'id': '41', 'type': 'True', 'children': []},{'id': '42', 'type': 'block', 'children': ['43', '52']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56', '136']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '55', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '56', 'type': 'block', 'children': ['57', '76', '85', '106']},{'id': '57', 'type': 'if_statement', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '59', 'type': 'block', 'children': ['60', '72']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'to_be_split'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "''"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '75', 'type': 'list', 'children': [], 'value': '[]'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '85', 'type': 'while_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '!='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '88', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '89', 'type': 'block', 'children': ['90', '97']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '106', 'type': 'if_statement', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '108', 'type': 'block', 'children': ['109', '122', '132']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'word'},{'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': 'string', 'children': [], 'value': "''"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'if_statement', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '124', 'type': 'block', 'children': ['125']},{'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': 'words'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '135', 'type': 'list', 'children': [], 'value': '[]'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '145', 'type': 'except_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'to_be_split'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "''"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '163', 'type': 'if_statement', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'to_be_split'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'to_be_split'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'split_strip'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '180', 'type': 'subscript', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'TAGGIT_SELECTIZE'},{'id': '184', 'type': 'string', 'children': [], 'value': "'DELIMITER'"},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'return_statement', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'words'} | def parse_tags(tagstring):
if not tagstring:
return []
tagstring = force_text(tagstring)
words = []
buffer = []
to_be_split = []
i = iter(tagstring)
try:
while True:
c = six.next(i)
if c == '"':
if buffer:
to_be_split.append(''.join(buffer))
buffer = []
c = six.next(i)
while c != '"':
buffer.append(c)
c = six.next(i)
if buffer:
word = ''.join(buffer).strip()
if word:
words.append(word)
buffer = []
else:
buffer.append(c)
except StopIteration:
if buffer:
to_be_split.append(''.join(buffer))
if to_be_split:
for chunk in to_be_split:
words.extend(split_strip(chunk, settings.TAGGIT_SELECTIZE['DELIMITER']))
words = list(set(words))
words.sort()
return words |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_by_unique_fields'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model_objs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '7', 'type': 'block', 'children': ['8', '26', '51']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '11', 'type': 'list_comprehension', 'children': ['12', '13', '20']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '20', 'type': 'if_clause', 'children': ['21']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'in'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'attname'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '26', 'type': 'function_definition', 'children': ['27', '28', '30']},{'id': '27', 'type': 'function_name', 'children': [], 'value': 'sort_key'},{'id': '28', 'type': 'parameters', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'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': 'tuple'},{'id': '34', 'type': 'generator_expression', 'children': ['35', '48']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_db_prep_save'},{'id': '39', 'type': 'argument_list', 'children': ['40', '47']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'attname'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'model_objs'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort_key'} | def _sort_by_unique_fields(model, model_objs, unique_fields):
unique_fields = [
field for field in model._meta.fields
if field.attname in unique_fields
]
def sort_key(model_obj):
return tuple(
field.get_db_prep_save(getattr(model_obj, field.attname),
connection)
for field in unique_fields
)
return sorted(model_objs, key=sort_key) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '6', 'type': 'block', 'children': ['7', '22', '78']},{'id': '7', 'type': 'if_statement', 'children': ['8', '19']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '16'], 'value': 'and'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '11', 'type': 'argument_list', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'expressions'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '22', 'type': 'if_statement', 'children': ['23', '38']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '31'], 'value': 'or'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '38', 'type': 'block', 'children': ['39', '56']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'conditional_expression', 'children': ['44', '52', '55'], 'value': 'if'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_compare'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'expressions'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'list', 'children': ['58'], 'value': '[jsonpath_rw.DatumInContext.wrap(\n [value for value in sorted(datum.value, key=key)])]'},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'jsonpath_rw'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'DatumInContext'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'wrap'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'list_comprehension', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '71', 'type': 'argument_list', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'datum'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'datum'} | def find(self, datum):
if isinstance(datum.value, dict) and self.expressions:
return datum
if isinstance(datum.value, dict) or isinstance(datum.value, list):
key = (functools.cmp_to_key(self._compare)
if self.expressions else None)
return [jsonpath_rw.DatumInContext.wrap(
[value for value in sorted(datum.value, key=key)])]
return datum |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_subset_riverid_index_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'river_id_list'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '68', '77', '86', '95']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'netcdf_river_indices_list'},{'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': 'valid_river_ids'},{'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': 'missing_river_ids'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'river_id'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'river_id_list'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'try_statement', 'children': ['24', '45']},{'id': '24', 'type': 'block', 'children': ['25', '38']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '31']},{'id': '27', 'type': 'attribute', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'netcdf_river_indices_list'},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get_river_index'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'river_id'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'valid_river_ids'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'river_id'},{'id': '45', 'type': 'except_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '47', 'type': 'block', 'children': ['48', '61']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '51', 'type': 'argument_list', 'children': ['52', '60']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'concatenated_string', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"ReachID {0} not found in netCDF dataset."'},{'id': '56', 'type': 'string', 'children': [], 'value': '" Skipping ..."'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'river_id'},{'id': '60', 'type': 'string', 'children': [], 'value': '"WARNING"'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'missing_river_ids'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'river_id'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'np_valid_river_indices_list'},{'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': 'netcdf_river_indices_list'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'np_valid_river_ids'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'valid_river_ids'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted_indexes'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'np_valid_river_indices_list'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'tuple', 'children': ['97', '100', '103']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'np_valid_river_indices_list'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted_indexes'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'np_valid_river_ids'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted_indexes'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'missing_river_ids'} | def get_subset_riverid_index_list(self, river_id_list):
netcdf_river_indices_list = []
valid_river_ids = []
missing_river_ids = []
for river_id in river_id_list:
try:
netcdf_river_indices_list \
.append(self.get_river_index(river_id))
valid_river_ids.append(river_id)
except IndexError:
log("ReachID {0} not found in netCDF dataset."
" Skipping ...".format(river_id),
"WARNING")
missing_river_ids.append(river_id)
np_valid_river_indices_list = np.array(netcdf_river_indices_list)
np_valid_river_ids = np.array(valid_river_ids)
sorted_indexes = np.argsort(np_valid_river_indices_list)
return(np_valid_river_indices_list[sorted_indexes],
np_valid_river_ids[sorted_indexes],
np.array(missing_river_ids)) |
Subsets and Splits