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', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_tree'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '24', '345']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'built'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'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': 'root'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted_fields'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '40', '48']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'not'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_fields'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_fields'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '!='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '61', '99', '224', '281']},{'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': 'field'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'XmlModel'},{'id': '61', 'type': 'block', 'children': ['62', '68', '88']},{'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': 'field'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'build_tree'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'if_statement', 'children': ['69', '86']},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '78'], 'value': 'and'},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '75'], 'value': 'and'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '85'], 'value': '=='},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'continue_statement', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '99', 'type': 'elif_clause', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '109', 'type': 'block', 'children': ['110', '220']},{'id': '110', 'type': 'if_statement', 'children': ['111', '116', '147', '186']},{'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': 'item'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'XmlField'},{'id': '116', 'type': 'block', 'children': ['117', '125', '138']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '136']},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '130'], 'value': 'and'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '135'], 'value': '=='},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'continue_statement', 'children': []},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '147', 'type': 'elif_clause', 'children': ['148', '153']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'XmlModel'},{'id': '153', 'type': 'block', 'children': ['154', '160', '175']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'build_tree'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'if_statement', 'children': ['161', '173']},{'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'and'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '172'], 'value': '=='},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'continue_statement', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '186', 'type': 'elif_clause', 'children': ['187', '198']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '191', 'type': 'tuple', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'text_type'},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '198', 'type': 'block', 'children': ['199', '211']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'etree'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'clean_xml'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '223', 'type': 'None', 'children': []},{'id': '224', 'type': 'elif_clause', 'children': ['225', '241']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '236'], 'value': '=='},{'id': '226', 'type': '()', 'children': ['227']},{'id': '227', 'type': 'boolean_operator', 'children': ['228', '231'], 'value': 'or'},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '231', 'type': 'attribute', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'block', 'children': ['242', '250', '268']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'if_statement', 'children': ['251', '266']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '262'], 'value': 'and'},{'id': '252', 'type': 'boolean_operator', 'children': ['253', '256'], 'value': 'and'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '261'], 'value': '=='},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '261', 'type': 'integer', 'children': [], 'value': '0'},{'id': '262', 'type': 'not_operator', 'children': ['263']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'continue_statement', 'children': []},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '281', 'type': 'else_clause', 'children': ['282']},{'id': '282', 'type': 'block', 'children': ['283', '302']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '286', 'type': 'list_comprehension', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '288', 'type': 'for_in_clause', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'n'},{'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': 'self'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'doc_root'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'iterdescendants'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '302', 'type': 'if_statement', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '304', 'type': 'block', 'children': ['305', '313', '332']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'if_statement', 'children': ['314', '330']},{'id': '314', 'type': '()', 'children': ['315']},{'id': '315', 'type': 'boolean_operator', 'children': ['316', '326'], 'value': 'and'},{'id': '316', 'type': 'boolean_operator', 'children': ['317', '320'], 'value': 'and'},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'drop_empty'},{'id': '320', 'type': 'comparison_operator', 'children': ['321', '325'], 'value': '=='},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'not_operator', 'children': ['327']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '330', 'type': 'block', 'children': ['331']},{'id': '331', 'type': 'continue_statement', 'children': []},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'ele'},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '344', 'type': 'integer', 'children': [], 'value': '0'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'built'},{'id': '350', 'type': 'True', 'children': []} | def build_tree(self):
if self.built:
return
self.doc_root = self.root.element()
for key in self.sorted_fields():
if key not in self._fields:
continue
field = self._fields[key]
if field != self.root:
if isinstance(field, XmlModel):
field.build_tree()
if (self.drop_empty and field.drop_empty
and len(field.doc_root) == 0):
continue
self.doc_root.append(field.doc_root)
elif isinstance(field, list):
for item in field:
if isinstance(item, XmlField):
ele = item.element()
if self.drop_empty and len(ele) == 0:
continue
self.doc_root.append(ele)
elif isinstance(item, XmlModel):
item.build_tree()
if self.drop_empty and len(item.doc_root) == 0:
continue
self.doc_root.append(item.doc_root)
elif isinstance(item, (six.text_type, six.string_types)):
ele = etree.fromstring(clean_xml(item))
self.doc_root.append(ele)
item = None
elif (field.parent or self.root.name) == self.root.name:
ele = field.element()
if self.drop_empty and len(ele) == 0 and not ele.text:
continue
ele = field.element(parent=self.doc_root)
else:
nodes = [n for n in self.doc_root.iterdescendants(
tag=field.parent)]
if nodes:
ele = field.element()
if (self.drop_empty and len(ele) == 0 and not ele.text):
continue
ele = field.element(parent=nodes[0])
self.built = True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'now'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '31', '54', '64']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'd'},{'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': 'datetime'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '22', 'type': 'attribute', 'children': ['23', '30']},{'id': '23', 'type': 'attribute', 'children': ['24', '29']},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'for_total_seconds'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36', '37'], 'value': '-'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '36', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45', '48', '51']},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'hour'},{'id': '44', 'type': 'integer', 'children': [], 'value': '0'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'minute'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'second'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'microsecond'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'msm'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '63'], 'value': '/'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'for_total_seconds'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'integer', 'children': [], 'value': '60'},{'id': '64', 'type': 'if_statement', 'children': ['65', '84', '109', '149']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '78'], 'value': '=='},{'id': '66', 'type': 'call', 'children': ['67', '76']},{'id': '67', 'type': 'attribute', 'children': ['68', '75']},{'id': '68', 'type': 'attribute', 'children': ['69', '74']},{'id': '69', 'type': 'subscript', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dZ"'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': '"%Y-%m-%dZ"'},{'id': '84', 'type': 'block', 'children': ['85', '107']},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '94']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'timestep'},{'id': '87', 'type': 'attribute', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'timesteps'},{'id': '94', 'type': 'block', 'children': ['95', '103']},{'id': '95', 'type': 'if_statement', 'children': ['96', '101']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '>'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'timestep'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'msm'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'break_statement', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'timestep'},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '109', 'type': 'elif_clause', 'children': ['110', '133']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '132'], 'value': '<'},{'id': '111', 'type': 'call', 'children': ['112', '131']},{'id': '112', 'type': 'attribute', 'children': ['113', '130']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '129'], 'value': '-'},{'id': '117', 'type': 'attribute', 'children': ['118', '128']},{'id': '118', 'type': 'subscript', 'children': ['119', '126']},{'id': '119', 'type': 'attribute', 'children': ['120', '125']},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'timesteps'},{'id': '126', 'type': 'unary_operator', 'children': ['127'], 'value': '-'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'integer', 'children': [], 'value': '14400'},{'id': '133', 'type': 'block', 'children': ['134', '147']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'timestep_to_return'},{'id': '137', 'type': 'subscript', 'children': ['138', '145']},{'id': '138', 'type': 'attribute', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'timesteps'},{'id': '145', 'type': 'unary_operator', 'children': ['146'], 'value': '-'},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'timestep_to_return'},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'return_statement', 'children': ['152']},{'id': '152', 'type': 'False', 'children': []} | def now(self):
now = None
d = datetime.datetime.now(tz=self.days[0].date.tzinfo)
for_total_seconds = d - \
d.replace(hour=0, minute=0, second=0, microsecond=0)
msm = for_total_seconds.total_seconds() / 60
if self.days[0].date.strftime("%Y-%m-%dZ") == d.strftime("%Y-%m-%dZ"):
for timestep in self.days[0].timesteps:
if timestep.name > msm:
break
now = timestep
return now
elif abs(self.days[0].timesteps[-1].date - d).total_seconds() < 14400:
timestep_to_return = self.days[0].timesteps[-1]
return timestep_to_return
else:
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '6', 'type': 'block', 'children': ['7', '13', '17', '23', '107', '189', '202', '210', '221', '227', '242', '247', '253', '268', '273', '280', '287']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'main_memory'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'MainMemory'},{'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': 'caches'},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'referred_caches'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '32']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33', '65', '79', '93']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Cache'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44']},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '44', 'type': 'dictionary_splat', 'children': ['45']},{'id': '45', 'type': 'dictionary_comprehension', 'children': ['46', '49', '58']},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'if_clause', 'children': ['59']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'not'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '61', 'type': 'list', 'children': ['62', '63', '64'], 'value': "['store_to', 'load_from', 'victims_to']"},{'id': '62', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'conf'},{'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': 'referred_caches'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '78', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '79', 'type': 'if_statement', 'children': ['80', '83']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'in'},{'id': '81', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'conf'},{'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': 'referred_caches'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '92', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'},{'id': '95', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'referred_caches'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '106', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '107', 'type': 'for_statement', 'children': ['108', '111', '116']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'block', 'children': ['117', '141', '165']},{'id': '117', 'type': 'if_statement', 'children': ['118', '127']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '122'], 'value': 'and'},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'in'},{'id': '120', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': 'is'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '125', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'set_store_to'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '140', 'type': 'string', 'children': [], 'value': "'store_to'"},{'id': '141', 'type': 'if_statement', 'children': ['142', '151']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '146'], 'value': 'and'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'in'},{'id': '144', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': 'is'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '149', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'set_load_from'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '164', 'type': 'string', 'children': [], 'value': "'load_from'"},{'id': '165', 'type': 'if_statement', 'children': ['166', '175']},{'id': '166', 'type': 'boolean_operator', 'children': ['167', '170'], 'value': 'and'},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'in'},{'id': '168', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': 'is'},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '173', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '174', 'type': 'None', 'children': []},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '183']},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'set_victims_to'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '188', 'type': 'string', 'children': [], 'value': "'victims_to'"},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '201'], 'value': '-'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '200', 'type': 'argument_list', 'children': []},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'referred_caches'},{'id': '202', 'type': 'assert_statement', 'children': ['203', '209']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '208'], 'value': '=='},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'string', 'children': [], 'value': '"Unable to find first cache level."'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '215', 'type': 'subscript', 'children': ['216', '220']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'last_level_load'},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '227', 'type': 'while_statement', 'children': ['228', '231']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'is'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '230', 'type': 'None', 'children': []},{'id': '231', 'type': 'block', 'children': ['232', '236']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'last_level_load'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'load_from'},{'id': '242', 'type': 'assert_statement', 'children': ['243', '246']},{'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'is'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'last_level_load'},{'id': '245', 'type': 'None', 'children': []},{'id': '246', 'type': 'string', 'children': [], 'value': '"Unable to find last cache level."'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'last_level_store'},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '253', 'type': 'while_statement', 'children': ['254', '257']},{'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': 'is'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '256', 'type': 'None', 'children': []},{'id': '257', 'type': 'block', 'children': ['258', '262']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'last_level_store'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'store_to'},{'id': '268', 'type': 'assert_statement', 'children': ['269', '272']},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': 'is'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'last_level_store'},{'id': '271', 'type': 'None', 'children': []},{'id': '272', 'type': 'string', 'children': [], 'value': '"Unable to find last cache level."'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'main_memory'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'load_to'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'last_level_load'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'main_memory'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'store_from'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'last_level_store'},{'id': '287', 'type': 'return_statement', 'children': ['288']},{'id': '288', 'type': 'expression_list', 'children': ['289', '294', '295']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'first_level'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'main_memory'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'caches'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'main_memory'} | def from_dict(cls, d):
main_memory = MainMemory()
caches = {}
referred_caches = set()
for name, conf in d.items():
caches[name] = Cache(name=name,
**{k: v for k, v in conf.items()
if k not in ['store_to', 'load_from', 'victims_to']})
if 'store_to' in conf:
referred_caches.add(conf['store_to'])
if 'load_from' in conf:
referred_caches.add(conf['load_from'])
if 'victims_to' in conf:
referred_caches.add(conf['victims_to'])
for name, conf in d.items():
if 'store_to' in conf and conf['store_to'] is not None:
caches[name].set_store_to(caches[conf['store_to']])
if 'load_from' in conf and conf['load_from'] is not None:
caches[name].set_load_from(caches[conf['load_from']])
if 'victims_to' in conf and conf['victims_to'] is not None:
caches[name].set_victims_to(caches[conf['victims_to']])
first_level = set(d.keys()) - referred_caches
assert len(first_level) == 1, "Unable to find first cache level."
first_level = caches[list(first_level)[0]]
last_level_load = c = first_level
while c is not None:
last_level_load = c
c = c.load_from
assert last_level_load is not None, "Unable to find last cache level."
last_level_store = c = first_level
while c is not None:
last_level_store = c
c = c.store_to
assert last_level_store is not None, "Unable to find last cache level."
main_memory.load_to(last_level_load)
main_memory.store_from(last_level_store)
return cls(first_level, main_memory), caches, main_memory |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_object_getattr'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '6', 'type': 'block', 'children': ['7', '9', '13', '39']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''Attribute getter for the objects to operate on.\n This function can be overridden in classes or instances of Query, Filter, and\n Order. Thus, a custom function to extract values to attributes can be\n specified, and the system can remain agnostic to the client's data model,\n without loosing query power.\n For example, the default implementation works with attributes and items::\n def _object_getattr(obj, field):\n if hasattr(obj, field):\n value = getattr(obj, field)\n elif field in obj:\n value = obj[field]\n return value\n Or consider a more complex, application-specific structure::\n def _object_getattr(version, field):\n if field in ['key', 'committed', 'created', 'hash']:\n return getattr(version, field)\n else:\n return version.attributes[field]['value']\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '28']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'value'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '28', 'type': 'elif_clause', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': 'value'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'} | def _object_getattr(obj, field):
'''Attribute getter for the objects to operate on.
This function can be overridden in classes or instances of Query, Filter, and
Order. Thus, a custom function to extract values to attributes can be
specified, and the system can remain agnostic to the client's data model,
without loosing query power.
For example, the default implementation works with attributes and items::
def _object_getattr(obj, field):
if hasattr(obj, field):
value = getattr(obj, field)
elif field in obj:
value = obj[field]
return value
Or consider a more complex, application-specific structure::
def _object_getattr(version, field):
if field in ['key', 'committed', 'created', 'hash']:
return getattr(version, field)
else:
return version.attributes[field]['value']
'''
value = None
if hasattr(obj, field):
value = getattr(obj, field)
elif field in obj:
value = obj[field]
return value |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '7', 'type': 'block', 'children': ['8', '10']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''Returns the elements in `items` sorted according to `orders`'''"},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'multipleOrderComparison'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'orders'} | def sorted(cls, items, orders):
'''Returns the elements in `items` sorted according to `orders`'''
return sorted(items, cmp=cls.multipleOrderComparison(orders)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_unique_fields'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '41']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '13']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '8', 'type': 'attribute', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'},{'id': '16', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '18', 'type': 'block', 'children': ['19', '26', '33']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'list_comprehension', 'children': ['35', '38']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '%'},{'id': '36', 'type': 'string', 'children': [], 'value': "'%s_id'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'unique_fields'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'list', 'children': [], 'value': '[]'} | def get_unique_fields(self):
for unique_together in self._meta.unique_together:
if 'sort_order' in unique_together:
unique_fields = list(unique_together)
unique_fields.remove('sort_order')
return ['%s_id' % f for f in unique_fields]
return [] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_sort_order_unique_together_with_something'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '32']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'unique_together'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'if_statement', 'children': ['19', '29']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'},{'id': '21', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': '>'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'False', 'children': []} | def _is_sort_order_unique_together_with_something(self):
unique_together = self._meta.unique_together
for fields in unique_together:
if 'sort_order' in fields and len(fields) > 1:
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_update'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'try_statement', 'children': ['7', '33']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'with_statement', 'children': ['9', '16']},{'id': '9', 'type': 'with_clause', 'children': ['10']},{'id': '10', 'type': 'with_item', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'atomic'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '32'], 'value': '+'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'except_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'IntegrityError'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '44']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'-sort_order'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '59']},{'id': '47', 'type': 'attribute', 'children': ['48', '58']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '+'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'} | def _update(qs):
try:
with transaction.atomic():
qs.update(sort_order=models.F('sort_order') + 1)
except IntegrityError:
for obj in qs.order_by('-sort_order'):
qs.filter(pk=obj.pk).update(sort_order=models.F('sort_order') + 1) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_orders'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'object_pks'},{'id': '6', 'type': 'block', 'children': ['7', '18', '42', '57', '105', '156']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'objects_to_sort'},{'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': 'filter'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pk__in'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'object_pks'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '21', 'type': 'subscript', 'children': ['22', '41']},{'id': '22', 'type': 'call', 'children': ['23', '34']},{'id': '23', 'type': 'attribute', 'children': ['24', '33']},{'id': '24', 'type': 'call', 'children': ['25', '32']},{'id': '25', 'type': 'attribute', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'aggregate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'Max'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'sort_order__max'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'objects_to_sort'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'values_list'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'flat'},{'id': '56', 'type': 'True', 'children': []},{'id': '57', 'type': 'if_statement', 'children': ['58', '67']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '63'], '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': 'identifier', 'children': [], 'value': 'orders'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'object_pks'},{'id': '67', 'type': 'block', 'children': ['68', '83', '100']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pks'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'objects_to_sort'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values_list'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'pk'"},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'flat'},{'id': '82', 'type': 'True', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'The following object_pks are not in this queryset: {}'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '93', '96']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '93', 'type': 'for_in_clause', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'object_pks'},{'id': '96', 'type': 'if_clause', 'children': ['97']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'not'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pks'},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '105', 'type': 'with_statement', 'children': ['106', '113']},{'id': '106', 'type': 'with_clause', 'children': ['107']},{'id': '107', 'type': 'with_item', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'transaction'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'atomic'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'block', 'children': ['114', '130']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'objects_to_sort'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '129'], 'value': '+'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'sort_order'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '130', 'type': 'for_statement', 'children': ['131', '134', '139']},{'id': '131', 'type': 'pattern_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'object_pks'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '152']},{'id': '142', 'type': 'attribute', 'children': ['143', '151']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'objects_to_sort'} | def set_orders(self, object_pks):
objects_to_sort = self.filter(pk__in=object_pks)
max_value = self.model.objects.all().aggregate(
models.Max('sort_order')
)['sort_order__max']
orders = list(objects_to_sort.values_list('sort_order', flat=True))
if len(orders) != len(object_pks):
pks = set(objects_to_sort.values_list('pk', flat=True))
message = 'The following object_pks are not in this queryset: {}'.format(
[pk for pk in object_pks if pk not in pks]
)
raise TypeError(message)
with transaction.atomic():
objects_to_sort.update(sort_order=models.F('sort_order') + max_value)
for pk, order in zip(object_pks, orders):
self.filter(pk=pk).update(sort_order=order)
return objects_to_sort |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_records'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'target_record_id'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'field_spec'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '13', 'type': 'string', 'children': [], 'value': "'orm'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'exclude_columns'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '30', '39', '53', '61', '68', '75', '87', '104', '109', '118']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'exclude_columns'},{'id': '24', 'type': 'None', 'children': []},{'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': 'exclude_columns'},{'id': '29', 'type': 'list', 'children': [], 'value': '[]'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'field_spec'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field_spec'},{'id': '38', 'type': 'dictionary', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'args0'},{'id': '56', 'type': 'tuple', 'children': ['57', '58', '59', '60']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'target_record_id'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args0'},{'id': '66', 'type': 'tuple', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'exclude_columns'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'args2'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'args0'},{'id': '73', 'type': 'tuple', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'field_spec'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'target_record_id'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'concatenated_string', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': '"You can\'t put the target record in the list or "'},{'id': '86', 'type': 'string', 'children': [], 'value': '"records to be merged."'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '90', 'type': 'attribute', 'children': ['91', '103']},{'id': '91', 'type': 'call', 'children': ['92', '102']},{'id': '92', 'type': 'attribute', 'children': ['93', '101']},{'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': 'env'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'browse'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '104', 'type': 'if_statement', 'children': ['105', '107']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_change_generic'},{'id': '112', 'type': 'argument_list', 'children': ['113', '115']},{'id': '113', 'type': 'list_splat', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '118', 'type': 'if_statement', 'children': ['119', '122', '181']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '121', 'type': 'string', 'children': [], 'value': "'orm'"},{'id': '122', 'type': 'block', 'children': ['123', '129', '135', '141', '147', '162', '170']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_change_many2one_refs_orm'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'list_splat', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_change_many2many_refs_orm'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'list_splat', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_change_reference_refs_orm'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'list_splat', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_change_translations_orm'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'list_splat', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '147', 'type': 'with_statement', 'children': ['148', '155']},{'id': '148', 'type': 'with_clause', 'children': ['149']},{'id': '149', 'type': 'with_item', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'norecompute'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_adjust_merged_values_orm'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'list_splat', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'args2'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'recompute'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'if_statement', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_delete_records_orm'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178', '179', '180']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'target_record_id'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183', '189', '195', '201']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_change_foreign_key_refs'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'list_splat', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_change_reference_refs_sql'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'list_splat', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_change_translations_sql'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'list_splat', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '201', 'type': 'if_statement', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_delete_records_sql'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210', '211']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'record_ids'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'target_record_id'} | def merge_records(env, model_name, record_ids, target_record_id,
field_spec=None, method='orm', delete=True,
exclude_columns=None):
if exclude_columns is None:
exclude_columns = []
if field_spec is None:
field_spec = {}
if isinstance(record_ids, list):
record_ids = tuple(record_ids)
args0 = (env, model_name, record_ids, target_record_id)
args = args0 + (exclude_columns, )
args2 = args0 + (field_spec, )
if target_record_id in record_ids:
raise Exception("You can't put the target record in the list or "
"records to be merged.")
record_ids = env[model_name].browse(record_ids).exists().ids
if not record_ids:
return
_change_generic(*args, method=method)
if method == 'orm':
_change_many2one_refs_orm(*args)
_change_many2many_refs_orm(*args)
_change_reference_refs_orm(*args)
_change_translations_orm(*args)
with env.norecompute():
_adjust_merged_values_orm(*args2)
env[model_name].recompute()
if delete:
_delete_records_orm(env, model_name, record_ids, target_record_id)
else:
_change_foreign_key_refs(*args)
_change_reference_refs_sql(*args)
_change_translations_sql(*args)
if delete:
_delete_records_sql(env, model_name, record_ids, target_record_id) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_existing_records'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cr'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '7', 'type': 'block', 'children': ['8', '146']},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '15']},{'id': '9', 'type': 'function_name', 'children': [], 'value': 'yield_element'},{'id': '10', 'type': 'parameters', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '25', '105']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': 'not'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '21', 'type': 'list', 'children': ['22', '23', '24'], 'value': "['openerp', 'odoo', 'data']"},{'id': '22', 'type': 'string', 'children': [], 'value': "'openerp'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'odoo'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '25', 'type': 'block', 'children': ['26', '81', '96', '102']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '31', 'type': 'string', 'children': [], 'value': "'record'"},{'id': '32', 'type': 'block', 'children': ['33', '41', '64', '74']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'xmlid'},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '40', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '50']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'},{'id': '43', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'xmlid'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'pattern_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'xmlid'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'xmlid'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cr'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'select id from ir_model_data where module=%s and name=%s'"},{'id': '71', 'type': 'tuple', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'xmlid'},{'id': '74', 'type': 'if_statement', 'children': ['75', '79']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'cr'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'rowcount'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'etree'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'tostring'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '95', 'type': 'string', 'children': [], 'value': "'unicode'"},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'yield', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '142']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'yield_element'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '117', 'type': 'conditional_expression', 'children': ['118', '130', '131'], 'value': 'if'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'etree'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'SubElement'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '127']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'etree'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '135', 'type': 'argument_list', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'yield', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'yield_element'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '159']},{'id': '151', 'type': 'attribute', 'children': ['152', '158']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'etree'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'getroot'},{'id': '159', 'type': 'argument_list', 'children': []} | def _get_existing_records(cr, fp, module_name):
def yield_element(node, path=None):
if node.tag not in ['openerp', 'odoo', 'data']:
if node.tag == 'record':
xmlid = node.attrib['id']
if '.' not in xmlid:
module = module_name
else:
module, xmlid = xmlid.split('.', 1)
cr.execute(
'select id from ir_model_data where module=%s and name=%s',
(module, xmlid)
)
if not cr.rowcount:
return
result = StringIO(etree.tostring(path, encoding='unicode'))
result.name = None
yield result
else:
for child in node:
for value in yield_element(
child,
etree.SubElement(path, node.tag, node.attrib)
if path else etree.Element(node.tag, node.attrib)
):
yield value
return yield_element(etree.parse(fp).getroot()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_ab'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '6', 'type': 'block', 'children': ['7', '9', '27', '67', '96', '107', '115', '123', '155', '187']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '9', 'type': 'try_statement', 'children': ['10', '18']},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '18', 'type': 'except_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'VariableCatch'},{'id': '20', 'type': 'block', 'children': ['21', '26']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'* ERROR :: <ab> must be an integer'"},{'id': '26', 'type': 'raise_statement', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'pab'},{'id': '30', 'type': 'list', 'children': ['31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66'], 'value': '[11, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26,\n 31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 45, 46,\n 51, 52, 53, 54, 55, 56, 61, 62, 63, 64, 65, 66]'},{'id': '31', 'type': 'integer', 'children': [], 'value': '11'},{'id': '32', 'type': 'integer', 'children': [], 'value': '12'},{'id': '33', 'type': 'integer', 'children': [], 'value': '13'},{'id': '34', 'type': 'integer', 'children': [], 'value': '14'},{'id': '35', 'type': 'integer', 'children': [], 'value': '15'},{'id': '36', 'type': 'integer', 'children': [], 'value': '16'},{'id': '37', 'type': 'integer', 'children': [], 'value': '21'},{'id': '38', 'type': 'integer', 'children': [], 'value': '22'},{'id': '39', 'type': 'integer', 'children': [], 'value': '23'},{'id': '40', 'type': 'integer', 'children': [], 'value': '24'},{'id': '41', 'type': 'integer', 'children': [], 'value': '25'},{'id': '42', 'type': 'integer', 'children': [], 'value': '26'},{'id': '43', 'type': 'integer', 'children': [], 'value': '31'},{'id': '44', 'type': 'integer', 'children': [], 'value': '32'},{'id': '45', 'type': 'integer', 'children': [], 'value': '33'},{'id': '46', 'type': 'integer', 'children': [], 'value': '34'},{'id': '47', 'type': 'integer', 'children': [], 'value': '35'},{'id': '48', 'type': 'integer', 'children': [], 'value': '36'},{'id': '49', 'type': 'integer', 'children': [], 'value': '41'},{'id': '50', 'type': 'integer', 'children': [], 'value': '42'},{'id': '51', 'type': 'integer', 'children': [], 'value': '43'},{'id': '52', 'type': 'integer', 'children': [], 'value': '44'},{'id': '53', 'type': 'integer', 'children': [], 'value': '45'},{'id': '54', 'type': 'integer', 'children': [], 'value': '46'},{'id': '55', 'type': 'integer', 'children': [], 'value': '51'},{'id': '56', 'type': 'integer', 'children': [], 'value': '52'},{'id': '57', 'type': 'integer', 'children': [], 'value': '53'},{'id': '58', 'type': 'integer', 'children': [], 'value': '54'},{'id': '59', 'type': 'integer', 'children': [], 'value': '55'},{'id': '60', 'type': 'integer', 'children': [], 'value': '56'},{'id': '61', 'type': 'integer', 'children': [], 'value': '61'},{'id': '62', 'type': 'integer', 'children': [], 'value': '62'},{'id': '63', 'type': 'integer', 'children': [], 'value': '63'},{'id': '64', 'type': 'integer', 'children': [], 'value': '64'},{'id': '65', 'type': 'integer', 'children': [], 'value': '65'},{'id': '66', 'type': 'integer', 'children': [], 'value': '66'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pab'},{'id': '71', 'type': 'block', 'children': ['72', '91']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'binary_operator', 'children': ['77', '87'], 'value': '+'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '86'], 'value': '+'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '85'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'},{'id': '80', 'type': 'string', 'children': [], 'value': "'* ERROR :: <ab> must be one of: '"},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pab'},{'id': '85', 'type': 'string', 'children': [], 'value': "';'"},{'id': '86', 'type': 'string', 'children': [], 'value': "' <ab> provided: '"},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '91', 'type': 'raise_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '96', 'type': 'if_statement', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '>'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '99', 'type': 'integer', 'children': [], 'value': '2'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '" Input ab : "'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': '>'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '%'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '113', 'type': 'integer', 'children': [], 'value': '10'},{'id': '114', 'type': 'integer', 'children': [], 'value': '3'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': '>'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '//'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '121', 'type': 'integer', 'children': [], 'value': '10'},{'id': '122', 'type': 'integer', 'children': [], 'value': '3'},{'id': '123', 'type': 'if_statement', 'children': ['124', '125', '149']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '128', '135']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '134', 'type': 'integer', 'children': [], 'value': '33'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '146'], 'value': '+'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '145'], 'value': '*'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '%'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '144', 'type': 'integer', 'children': [], 'value': '10'},{'id': '145', 'type': 'integer', 'children': [], 'value': '10'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '//'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '148', 'type': 'integer', 'children': [], 'value': '10'},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'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': 'ab_calc'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '>'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '158', 'type': 'integer', 'children': [], 'value': '2'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'if_statement', 'children': ['161', '166', '179']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'in'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '163', 'type': 'list', 'children': ['164', '165'], 'value': '[36, 63]'},{'id': '164', 'type': 'integer', 'children': [], 'value': '36'},{'id': '165', 'type': 'integer', 'children': [], 'value': '63'},{'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': 'print'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '178'], 'value': '+'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '+'},{'id': '173', 'type': 'string', 'children': [], 'value': '"\\n> <ab> IS "'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '178', 'type': 'string', 'children': [], 'value': '" WHICH IS ZERO; returning"'},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': '" Calculated ab : "'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'expression_list', 'children': ['189', '190', '191']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'mrec'} | def check_ab(ab, verb):
r
try:
ab = int(ab)
except VariableCatch:
print('* ERROR :: <ab> must be an integer')
raise
pab = [11, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26,
31, 32, 33, 34, 35, 36, 41, 42, 43, 44, 45, 46,
51, 52, 53, 54, 55, 56, 61, 62, 63, 64, 65, 66]
if ab not in pab:
print('* ERROR :: <ab> must be one of: ' + str(pab) + ';' +
' <ab> provided: ' + str(ab))
raise ValueError('ab')
if verb > 2:
print(" Input ab : ", ab)
msrc = ab % 10 > 3
mrec = ab // 10 > 3
if mrec:
if msrc:
ab_calc = ab - 33
else:
ab_calc = ab % 10*10 + ab // 10
else:
ab_calc = ab
if verb > 2:
if ab in [36, 63]:
print("\n> <ab> IS "+str(ab)+" WHICH IS ZERO; returning")
else:
print(" Calculated ab : ", ab_calc)
return ab_calc, msrc, mrec |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_opt'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '9', 'type': 'block', 'children': ['10', '12', '16', '40', '44', '60', '91', '134']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '19', 'type': 'string', 'children': [], 'value': "'parallel'"},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '23', '30']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'numexpr'},{'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': 'use_ne_eval'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'numexpr'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'evaluate'},{'id': '30', 'type': 'elif_clause', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '>'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'numexpr_msg'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'lagged_splined_fht'},{'id': '43', 'type': 'False', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '=='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '47', 'type': 'string', 'children': [], 'value': "'fht'"},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '55']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '!='},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'lagged_splined_fht'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'if_statement', 'children': ['61', '68', '77']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '67'], 'value': 'or'},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': "['hqwe', 'hquad']"},{'id': '65', 'type': 'string', 'children': [], 'value': "'hqwe'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'hquad'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'lagged_splined_fht'},{'id': '68', 'type': 'block', 'children': ['69', '73']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'loop_freq'},{'id': '72', 'type': 'True', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'loop_off'},{'id': '76', 'type': 'False', 'children': []},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79', '85']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'loop_off'},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '=='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '84', 'type': 'string', 'children': [], 'value': "'off'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'loop_freq'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '90', 'type': 'string', 'children': [], 'value': "'freq'"},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '>'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '94', 'type': 'integer', 'children': [], 'value': '2'},{'id': '95', 'type': 'block', 'children': ['96', '111']},{'id': '96', 'type': 'if_statement', 'children': ['97', '98', '104']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': '" Kernel Opt. : Use parallel"'},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': '" Kernel Opt. : None"'},{'id': '111', 'type': 'if_statement', 'children': ['112', '113', '119', '127']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'loop_off'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': '" Loop over : Offsets"'},{'id': '119', 'type': 'elif_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'loop_freq'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': '" Loop over : Frequencies"'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': '" Loop over : None (all vectorized)"'},{'id': '134', 'type': 'return_statement', 'children': ['135']},{'id': '135', 'type': 'expression_list', 'children': ['136', '137', '138']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'loop_freq'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'loop_off'} | def check_opt(opt, loop, ht, htarg, verb):
r
use_ne_eval = False
if opt == 'parallel':
if numexpr:
use_ne_eval = numexpr.evaluate
elif verb > 0:
print(numexpr_msg)
lagged_splined_fht = False
if ht == 'fht':
if htarg[1] != 0:
lagged_splined_fht = True
if ht in ['hqwe', 'hquad'] or lagged_splined_fht:
loop_freq = True
loop_off = False
else:
loop_off = loop == 'off'
loop_freq = loop == 'freq'
if verb > 2:
if use_ne_eval:
print(" Kernel Opt. : Use parallel")
else:
print(" Kernel Opt. : None")
if loop_off:
print(" Loop over : Offsets")
elif loop_freq:
print(" Loop over : Frequencies")
else:
print(" Loop over : None (all vectorized)")
return use_ne_eval, loop_freq, loop_off |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_abs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'srcazm'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'srcdip'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'recazm'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'recdip'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '11', 'type': 'block', 'children': ['12', '14', '35', '42', '70', '86', '97', '149', '160', '214', '225', '277', '288', '342', '352', '366']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'list', 'children': ['23', '27', '31'], 'value': '[[11, 12, 13], [21, 22, 23], [31, 32, 33]]'},{'id': '23', 'type': 'list', 'children': ['24', '25', '26'], 'value': '[11, 12, 13]'},{'id': '24', 'type': 'integer', 'children': [], 'value': '11'},{'id': '25', 'type': 'integer', 'children': [], 'value': '12'},{'id': '26', 'type': 'integer', 'children': [], 'value': '13'},{'id': '27', 'type': 'list', 'children': ['28', '29', '30'], 'value': '[21, 22, 23]'},{'id': '28', 'type': 'integer', 'children': [], 'value': '21'},{'id': '29', 'type': 'integer', 'children': [], 'value': '22'},{'id': '30', 'type': 'integer', 'children': [], 'value': '23'},{'id': '31', 'type': 'list', 'children': ['32', '33', '34'], 'value': '[31, 32, 33]'},{'id': '32', 'type': 'integer', 'children': [], 'value': '31'},{'id': '33', 'type': 'integer', 'children': [], 'value': '32'},{'id': '34', 'type': 'integer', 'children': [], 'value': '33'},{'id': '35', 'type': 'if_statement', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'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': 'ab_calc'},{'id': '41', 'type': 'integer', 'children': [], 'value': '3'},{'id': '42', 'type': 'if_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '44', 'type': 'block', 'children': ['45', '49']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'augmented_assignment', 'children': ['47', '48'], 'value': '+='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '48', 'type': 'integer', 'children': [], 'value': '30'},{'id': '49', 'type': 'if_statement', 'children': ['50', '51', '56']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '-='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '55', 'type': 'integer', 'children': [], 'value': '33'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '67'], 'value': '+'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '*'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '65', 'type': 'integer', 'children': [], 'value': '10'},{'id': '66', 'type': 'integer', 'children': [], 'value': '10'},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '//'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '69', 'type': 'integer', 'children': [], 'value': '10'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '77', 'type': 'argument_list', 'children': ['78', '83']},{'id': '78', 'type': 'binary_operator', 'children': ['79', '82'], 'value': '+'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '*'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '89', 'type': 'subscript', 'children': ['90', '96']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'srcazm'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'if_statement', 'children': ['98', '112']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'allclose'},{'id': '102', 'type': 'argument_list', 'children': ['103', '111']},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'srcazm'},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'binary_operator', 'children': ['107', '110'], 'value': '/'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '110', 'type': 'integer', 'children': [], 'value': '2'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '130', '139']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'isclose'},{'id': '118', 'type': 'argument_list', 'children': ['119', '129']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '128'], 'value': '%'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '//'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '122', 'type': '()', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '/'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '127', 'type': 'integer', 'children': [], 'value': '2'},{'id': '128', 'type': 'integer', 'children': [], 'value': '2'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'augmented_assignment', 'children': ['133', '138'], 'value': '*='},{'id': '133', 'type': 'subscript', 'children': ['134', '135', '137']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '135', 'type': 'slice', 'children': ['136']},{'id': '136', 'type': 'colon', 'children': []},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'False', 'children': []},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'augmented_assignment', 'children': ['143', '148'], 'value': '*='},{'id': '143', 'type': 'subscript', 'children': ['144', '145', '147']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '145', 'type': 'slice', 'children': ['146']},{'id': '146', 'type': 'colon', 'children': []},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'False', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '152', 'type': 'subscript', 'children': ['153', '159']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'srcdip'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'if_statement', 'children': ['161', '175']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'allclose'},{'id': '165', 'type': 'argument_list', 'children': ['166', '174']},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'srcdip'},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '173'], 'value': '/'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '173', 'type': 'integer', 'children': [], 'value': '2'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'if_statement', 'children': ['177', '193', '202']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'isclose'},{'id': '181', 'type': 'argument_list', 'children': ['182', '192']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '191'], 'value': '%'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '//'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '185', 'type': '()', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '190'], 'value': '/'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '190', 'type': 'integer', 'children': [], 'value': '2'},{'id': '191', 'type': 'integer', 'children': [], 'value': '2'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '201'], 'value': '*='},{'id': '196', 'type': 'subscript', 'children': ['197', '198', '200']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '198', 'type': 'slice', 'children': ['199']},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'integer', 'children': [], 'value': '2'},{'id': '201', 'type': 'False', 'children': []},{'id': '202', 'type': 'else_clause', 'children': ['203']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'augmented_assignment', 'children': ['206', '213'], 'value': '*='},{'id': '206', 'type': 'subscript', 'children': ['207', '208', '210']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '208', 'type': 'slice', 'children': ['209']},{'id': '209', 'type': 'colon', 'children': []},{'id': '210', 'type': 'slice', 'children': ['211', '212']},{'id': '211', 'type': 'colon', 'children': []},{'id': '212', 'type': 'integer', 'children': [], 'value': '2'},{'id': '213', 'type': 'False', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '217', 'type': 'subscript', 'children': ['218', '224']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'recazm'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'if_statement', 'children': ['226', '240']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'allclose'},{'id': '230', 'type': 'argument_list', 'children': ['231', '239']},{'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '%'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'recazm'},{'id': '233', 'type': '()', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '/'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '238', 'type': 'integer', 'children': [], 'value': '2'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'if_statement', 'children': ['242', '258', '267']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'isclose'},{'id': '246', 'type': 'argument_list', 'children': ['247', '257']},{'id': '247', 'type': 'binary_operator', 'children': ['248', '256'], 'value': '%'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '//'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '250', 'type': '()', 'children': ['251']},{'id': '251', 'type': 'binary_operator', 'children': ['252', '255'], 'value': '/'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '255', 'type': 'integer', 'children': [], 'value': '2'},{'id': '256', 'type': 'integer', 'children': [], 'value': '2'},{'id': '257', 'type': 'integer', 'children': [], 'value': '0'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'augmented_assignment', 'children': ['261', '266'], 'value': '*='},{'id': '261', 'type': 'subscript', 'children': ['262', '263', '264']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '263', 'type': 'integer', 'children': [], 'value': '1'},{'id': '264', 'type': 'slice', 'children': ['265']},{'id': '265', 'type': 'colon', 'children': []},{'id': '266', 'type': 'False', 'children': []},{'id': '267', 'type': 'else_clause', 'children': ['268']},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'augmented_assignment', 'children': ['271', '276'], 'value': '*='},{'id': '271', 'type': 'subscript', 'children': ['272', '273', '274']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '273', 'type': 'integer', 'children': [], 'value': '0'},{'id': '274', 'type': 'slice', 'children': ['275']},{'id': '275', 'type': 'colon', 'children': []},{'id': '276', 'type': 'False', 'children': []},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '280', 'type': 'subscript', 'children': ['281', '287']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'recdip'},{'id': '287', 'type': 'integer', 'children': [], 'value': '0'},{'id': '288', 'type': 'if_statement', 'children': ['289', '303']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'allclose'},{'id': '293', 'type': 'argument_list', 'children': ['294', '302']},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'recdip'},{'id': '296', 'type': '()', 'children': ['297']},{'id': '297', 'type': 'binary_operator', 'children': ['298', '301'], 'value': '/'},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '301', 'type': 'integer', 'children': [], 'value': '2'},{'id': '302', 'type': 'integer', 'children': [], 'value': '0'},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'if_statement', 'children': ['305', '321', '330']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'isclose'},{'id': '309', 'type': 'argument_list', 'children': ['310', '320']},{'id': '310', 'type': 'binary_operator', 'children': ['311', '319'], 'value': '%'},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '//'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '313', 'type': '()', 'children': ['314']},{'id': '314', 'type': 'binary_operator', 'children': ['315', '318'], 'value': '/'},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '318', 'type': 'integer', 'children': [], 'value': '2'},{'id': '319', 'type': 'integer', 'children': [], 'value': '2'},{'id': '320', 'type': 'integer', 'children': [], 'value': '0'},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'augmented_assignment', 'children': ['324', '329'], 'value': '*='},{'id': '324', 'type': 'subscript', 'children': ['325', '326', '327']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '326', 'type': 'integer', 'children': [], 'value': '2'},{'id': '327', 'type': 'slice', 'children': ['328']},{'id': '328', 'type': 'colon', 'children': []},{'id': '329', 'type': 'False', 'children': []},{'id': '330', 'type': 'else_clause', 'children': ['331']},{'id': '331', 'type': 'block', 'children': ['332']},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'augmented_assignment', 'children': ['334', '341'], 'value': '*='},{'id': '334', 'type': 'subscript', 'children': ['335', '336', '339']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '336', 'type': 'slice', 'children': ['337', '338']},{'id': '337', 'type': 'colon', 'children': []},{'id': '338', 'type': 'integer', 'children': [], 'value': '2'},{'id': '339', 'type': 'slice', 'children': ['340']},{'id': '340', 'type': 'colon', 'children': []},{'id': '341', 'type': 'False', 'children': []},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '345', 'type': 'call', 'children': ['346', '351']},{'id': '346', 'type': 'attribute', 'children': ['347', '350']},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'bab'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'ravel'},{'id': '351', 'type': 'argument_list', 'children': []},{'id': '352', 'type': 'if_statement', 'children': ['353', '356']},{'id': '353', 'type': 'comparison_operator', 'children': ['354', '355'], 'value': '>'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '355', 'type': 'integer', 'children': [], 'value': '2'},{'id': '356', 'type': 'block', 'children': ['357']},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '360', 'type': 'argument_list', 'children': ['361', '362']},{'id': '361', 'type': 'string', 'children': [], 'value': '" Required ab\'s : "'},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': '_strvar'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '366', 'type': 'return_statement', 'children': ['367']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'ab_calc'} | def get_abs(msrc, mrec, srcazm, srcdip, recazm, recdip, verb):
r
ab_calc = np.array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
if msrc:
ab_calc += 3
if mrec:
ab_calc += 30
if msrc:
ab_calc -= 33
else:
ab_calc = ab_calc % 10*10 + ab_calc // 10
bab = np.asarray(ab_calc*0+1, dtype=bool)
check = np.atleast_1d(srcazm)[0]
if np.allclose(srcazm % (np.pi/2), 0):
if np.isclose(check // (np.pi/2) % 2, 0):
bab[:, 1] *= False
else:
bab[:, 0] *= False
check = np.atleast_1d(srcdip)[0]
if np.allclose(srcdip % (np.pi/2), 0):
if np.isclose(check // (np.pi/2) % 2, 0):
bab[:, 2] *= False
else:
bab[:, :2] *= False
check = np.atleast_1d(recazm)[0]
if np.allclose(recazm % (np.pi/2), 0):
if np.isclose(check // (np.pi/2) % 2, 0):
bab[1, :] *= False
else:
bab[0, :] *= False
check = np.atleast_1d(recdip)[0]
if np.allclose(recdip % (np.pi/2), 0):
if np.isclose(check // (np.pi/2) % 2, 0):
bab[2, :] *= False
else:
bab[:2, :] *= False
ab_calc = ab_calc[bab].ravel()
if verb > 2:
print(" Required ab's : ", _strvar(ab_calc))
return ab_calc |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'spline_backwards_hankel'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '7', 'type': 'block', 'children': ['8', '10', '18', '121']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '25']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '21', 'type': 'list', 'children': ['22', '23', '24'], 'value': "['fht', 'qwe', 'hqwe']"},{'id': '22', 'type': 'string', 'children': [], 'value': "'fht'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'qwe'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'hqwe'"},{'id': '25', 'type': 'block', 'children': ['26', '65']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '41']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '29', 'type': 'string', 'children': [], 'value': "'fht'"},{'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': 'htarg'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_check_targ'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '38', 'type': 'list', 'children': ['39', '40'], 'value': "['fhtfilt', 'pts_per_dec']"},{'id': '39', 'type': 'string', 'children': [], 'value': "'fhtfilt'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'pts_per_dec'"},{'id': '41', 'type': 'elif_clause', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '44', 'type': 'list', 'children': ['45', '46'], 'value': "['qwe', 'hqwe']"},{'id': '45', 'type': 'string', 'children': [], 'value': "'qwe'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'hqwe'"},{'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': 'htarg'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_check_targ'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '55', 'type': 'list', 'children': ['56', '57', '58', '59', '60', '61', '62', '63', '64'], 'value': "['rtol', 'atol', 'nquad', 'maxint',\n 'pts_per_dec', 'diff_quad', 'a', 'b', 'limit']"},{'id': '56', 'type': 'string', 'children': [], 'value': "'rtol'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'atol'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'nquad'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'maxint'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'pts_per_dec'"},{'id': '61', 'type': 'string', 'children': [], 'value': "'diff_quad'"},{'id': '62', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '68', 'type': 'string', 'children': [], 'value': "'spline'"},{'id': '69', 'type': 'block', 'children': ['70', '79', '87', '91']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mesg'},{'id': '73', 'type': '()', 'children': ['74']},{'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '+'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'},{'id': '76', 'type': 'string', 'children': [], 'value': '"\\n The use of `opt=\'spline\'` is deprecated and will "'},{'id': '77', 'type': 'string', 'children': [], 'value': '"be removed\\n in v2.0.0; use the corresponding "'},{'id': '78', 'type': 'string', 'children': [], 'value': '"setting in `htarg`."'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mesg'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'not'},{'id': '93', 'type': 'string', 'children': [], 'value': "'pts_per_dec'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'if_statement', 'children': ['97', '100', '108']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '=='},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '99', 'type': 'string', 'children': [], 'value': "'fht'"},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '105', 'type': 'string', 'children': [], 'value': "'pts_per_dec'"},{'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'elif_clause', 'children': ['109', '114']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '111', 'type': 'list', 'children': ['112', '113'], 'value': "['qwe', 'hqwe']"},{'id': '112', 'type': 'string', 'children': [], 'value': "'qwe'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'hqwe'"},{'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': 'htarg'},{'id': '119', 'type': 'string', 'children': [], 'value': "'pts_per_dec'"},{'id': '120', 'type': 'integer', 'children': [], 'value': '80'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'expression_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'opt'} | def spline_backwards_hankel(ht, htarg, opt):
r
ht = ht.lower()
if ht in ['fht', 'qwe', 'hqwe']:
if ht == 'fht':
htarg = _check_targ(htarg, ['fhtfilt', 'pts_per_dec'])
elif ht in ['qwe', 'hqwe']:
htarg = _check_targ(htarg, ['rtol', 'atol', 'nquad', 'maxint',
'pts_per_dec', 'diff_quad', 'a', 'b', 'limit'])
if opt == 'spline':
mesg = ("\n The use of `opt='spline'` is deprecated and will " +
"be removed\n in v2.0.0; use the corresponding " +
"setting in `htarg`.")
warnings.warn(mesg, DeprecationWarning)
opt = None
if 'pts_per_dec' not in htarg:
if ht == 'fht':
htarg['pts_per_dec'] = -1
elif ht in ['qwe', 'hqwe']:
htarg['pts_per_dec'] = 80
return htarg, opt |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dipole_k'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '13', '16', '19', '22', '25', '28']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '12', 'type': 'integer', 'children': [], 'value': '11'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '30', 'type': 'integer', 'children': [], 'value': '2'},{'id': '31', 'type': 'block', 'children': ['32', '34', '41', '56', '68', '82', '91', '102', '113', '124', '137', '149', '159', '169', '279', '380', '387']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 't0'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'printstartfinish'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'modl'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'check_model'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49', '50', '51', '52', '53', '54', '55']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '54', 'type': 'False', 'children': []},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '67']},{'id': '58', 'type': 'pattern_list', 'children': ['59', '60', '61', '62', '63', '64', '65', '66']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'modl'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'check_frequency'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '76', '77', '78', '79', '80', '81']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '90']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86', '87', '88', '89']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '97']},{'id': '93', 'type': 'pattern_list', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'check_ab'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '107']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'nsrc'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'check_dipole'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '111', 'type': 'string', 'children': [], 'value': "'src'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nrec'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'check_dipole'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '122', 'type': 'string', 'children': [], 'value': "'rec'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get_off_ang'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134', '135', '136']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'nsrc'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'nrec'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'kernel'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'angle_factor'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146', '147', '148']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'get_layer_nr'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '164']},{'id': '161', 'type': 'pattern_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_layer_nr'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '169', 'type': 'if_statement', 'children': ['170', '184', '235']},{'id': '170', 'type': 'boolean_operator', 'children': ['171', '176'], 'value': 'and'},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '=='},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '183'], 'value': '=='},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '183', 'type': 'integer', 'children': [], 'value': '2'},{'id': '184', 'type': 'block', 'children': ['185', '210']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '192', 'type': 'argument_list', 'children': ['193', '207']},{'id': '193', 'type': 'tuple', 'children': ['194', '197', '202']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'subscript', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '206', 'type': 'integer', 'children': [], 'value': '1'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '217', 'type': 'argument_list', 'children': ['218', '232']},{'id': '218', 'type': 'tuple', 'children': ['219', '222', '227']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '222', 'type': 'subscript', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '235', 'type': 'else_clause', 'children': ['236']},{'id': '236', 'type': 'block', 'children': ['237', '258']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '244', 'type': 'argument_list', 'children': ['245', '255']},{'id': '245', 'type': 'tuple', 'children': ['246', '249', '252']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '265', 'type': 'argument_list', 'children': ['266', '276']},{'id': '266', 'type': 'tuple', 'children': ['267', '270', '273']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '279', 'type': 'if_statement', 'children': ['280', '284']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': 'not'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '282', 'type': 'list', 'children': ['283'], 'value': '[36, ]'},{'id': '283', 'type': 'integer', 'children': [], 'value': '36'},{'id': '284', 'type': 'block', 'children': ['285', '316', '354', '363']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '291']},{'id': '287', 'type': 'pattern_list', 'children': ['288', '289', '290']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'J0'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'J1'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'J0b'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'kernel'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '295', 'type': 'argument_list', 'children': ['296', '297', '298', '299', '300', '301', '302', '303', '304', '305', '311', '312', '313', '314', '315']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'ab_calc'},{'id': '312', 'type': 'False', 'children': []},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '315', 'type': 'False', 'children': []},{'id': '316', 'type': 'if_statement', 'children': ['317', '320']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '319'], 'value': 'is'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'J1'},{'id': '319', 'type': 'None', 'children': []},{'id': '320', 'type': 'block', 'children': ['321', '333']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'augmented_assignment', 'children': ['323', '324'], 'value': '+='},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '324', 'type': 'binary_operator', 'children': ['325', '332'], 'value': '*'},{'id': '325', 'type': 'subscript', 'children': ['326', '327', '329']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '327', 'type': 'slice', 'children': ['328']},{'id': '328', 'type': 'colon', 'children': []},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'newaxis'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'J1'},{'id': '333', 'type': 'if_statement', 'children': ['334', '345']},{'id': '334', 'type': 'comparison_operator', 'children': ['335', '336'], 'value': 'in'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '336', 'type': 'list', 'children': ['337', '338', '339', '340', '341', '342', '343', '344'], 'value': '[11, 12, 21, 22, 14, 24, 15, 25]'},{'id': '337', 'type': 'integer', 'children': [], 'value': '11'},{'id': '338', 'type': 'integer', 'children': [], 'value': '12'},{'id': '339', 'type': 'integer', 'children': [], 'value': '21'},{'id': '340', 'type': 'integer', 'children': [], 'value': '22'},{'id': '341', 'type': 'integer', 'children': [], 'value': '14'},{'id': '342', 'type': 'integer', 'children': [], 'value': '24'},{'id': '343', 'type': 'integer', 'children': [], 'value': '15'},{'id': '344', 'type': 'integer', 'children': [], 'value': '25'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'augmented_assignment', 'children': ['348', '349'], 'value': '/='},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '349', 'type': 'subscript', 'children': ['350', '351', '353']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '351', 'type': 'slice', 'children': ['352']},{'id': '352', 'type': 'colon', 'children': []},{'id': '353', 'type': 'None', 'children': []},{'id': '354', 'type': 'if_statement', 'children': ['355', '358']},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': 'is'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'J0'},{'id': '357', 'type': 'None', 'children': []},{'id': '358', 'type': 'block', 'children': ['359']},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'augmented_assignment', 'children': ['361', '362'], 'value': '+='},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'J0'},{'id': '363', 'type': 'if_statement', 'children': ['364', '367']},{'id': '364', 'type': 'comparison_operator', 'children': ['365', '366'], 'value': 'is'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'J0b'},{'id': '366', 'type': 'None', 'children': []},{'id': '367', 'type': 'block', 'children': ['368']},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'augmented_assignment', 'children': ['370', '371'], 'value': '+='},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '371', 'type': 'binary_operator', 'children': ['372', '379'], 'value': '*'},{'id': '372', 'type': 'subscript', 'children': ['373', '374', '376']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '374', 'type': 'slice', 'children': ['375']},{'id': '375', 'type': 'colon', 'children': []},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'newaxis'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'J0b'},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'printstartfinish'},{'id': '383', 'type': 'argument_list', 'children': ['384', '385', '386']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 't0'},{'id': '386', 'type': 'integer', 'children': [], 'value': '1'},{'id': '387', 'type': 'return_statement', 'children': ['388']},{'id': '388', 'type': 'expression_list', 'children': ['389', '395']},{'id': '389', 'type': 'call', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '395', 'type': 'call', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'PJ1'} | def dipole_k(src, rec, depth, res, freq, wavenumber, ab=11, aniso=None,
epermH=None, epermV=None, mpermH=None, mpermV=None, verb=2):
r
t0 = printstartfinish(verb)
modl = check_model(depth, res, aniso, epermH, epermV, mpermH, mpermV,
False, verb)
depth, res, aniso, epermH, epermV, mpermH, mpermV, _ = modl
f = check_frequency(freq, res, aniso, epermH, epermV, mpermH, mpermV, verb)
freq, etaH, etaV, zetaH, zetaV = f
ab_calc, msrc, mrec = check_ab(ab, verb)
src, nsrc = check_dipole(src, 'src', verb)
rec, nrec = check_dipole(rec, 'rec', verb)
off, angle = get_off_ang(src, rec, nsrc, nrec, verb)
factAng = kernel.angle_factor(angle, ab, msrc, mrec)
lsrc, zsrc = get_layer_nr(src, depth)
lrec, zrec = get_layer_nr(rec, depth)
if off.size == 1 and np.ndim(wavenumber) == 2:
PJ0 = np.zeros((freq.size, wavenumber.shape[0], wavenumber.shape[1]),
dtype=complex)
PJ1 = np.zeros((freq.size, wavenumber.shape[0], wavenumber.shape[1]),
dtype=complex)
else:
PJ0 = np.zeros((freq.size, off.size, wavenumber.size), dtype=complex)
PJ1 = np.zeros((freq.size, off.size, wavenumber.size), dtype=complex)
if ab_calc not in [36, ]:
J0, J1, J0b = kernel.wavenumber(zsrc, zrec, lsrc, lrec, depth, etaH,
etaV, zetaH, zetaV,
np.atleast_2d(wavenumber), ab_calc,
False, msrc, mrec, False)
if J1 is not None:
PJ1 += factAng[:, np.newaxis]*J1
if ab in [11, 12, 21, 22, 14, 24, 15, 25]:
PJ1 /= off[:, None]
if J0 is not None:
PJ0 += J0
if J0b is not None:
PJ0 += factAng[:, np.newaxis]*J0b
printstartfinish(verb, t0, 1)
return np.squeeze(PJ0), np.squeeze(PJ1) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_result'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'prntres'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '22', '31', '42', '53', '64', '76', '88', '279', '299', '306', '393', '413', '420', '427', '436', '448']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '12', 'type': 'if_statement', 'children': ['13', '15']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '15', 'type': 'block', 'children': ['16', '21']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'plt_msg'},{'id': '21', 'type': 'return_statement', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'prntres'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'print_result'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '34', 'type': 'subscript', 'children': ['35', '38', '39', '41']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '37', 'type': 'integer', 'children': [], 'value': '2'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'slice', 'children': ['40']},{'id': '40', 'type': 'colon', 'children': []},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '45', 'type': 'subscript', 'children': ['46', '49', '50', '51']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '48', 'type': 'integer', 'children': [], 'value': '2'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'slice', 'children': ['52']},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'minfield'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '63', 'type': 'integer', 'children': [], 'value': '3'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': '"Brute force result"'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '73', 'type': 'tuple', 'children': ['74', '75']},{'id': '74', 'type': 'float', 'children': [], 'value': '9.5'},{'id': '75', 'type': 'float', 'children': [], 'value': '4.5'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'subplots_adjust'},{'id': '81', 'type': 'argument_list', 'children': ['82', '85']},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'wspace'},{'id': '84', 'type': 'float', 'children': [], 'value': '.4'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'bottom'},{'id': '87', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '88', 'type': 'if_statement', 'children': ['89', '100']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '95'], 'value': 'or'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '>'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': '>'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'block', 'children': ['101', '108', '170']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'subplot'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'integer', 'children': [], 'value': '121'},{'id': '108', 'type': 'if_statement', 'children': ['109', '114', '143']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'full'},{'id': '112', 'type': 'integer', 'children': [], 'value': '4'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'block', 'children': ['115', '122', '126', '135']},{'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': 'plt'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': '"Minimal recovered fields"'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '125', 'type': 'string', 'children': [], 'value': "'Minimal recovered amplitude (log10)'"},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'minfield'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'viridis'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145', '152', '156', '162']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': '"Maximum recovered r"'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '155', 'type': 'string', 'children': [], 'value': "'Maximum recovered r'"},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '/'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'minfield'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'viridis_r'},{'id': '170', 'type': 'if_statement', 'children': ['171', '176', '199', '228']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '=='},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'block', 'children': ['177', '185', '192']},{'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': 'plt'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'string', 'children': [], 'value': "'Spacing'"},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '199', 'type': 'elif_clause', 'children': ['200', '205']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '204'], 'value': '=='},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'block', 'children': ['206', '214', '221']},{'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': 'plt'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'plt'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': "'Shift'"},{'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': 'plt'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '228', 'type': 'else_clause', 'children': ['229']},{'id': '229', 'type': 'block', 'children': ['230', '247', '259', '266', '273']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '233', 'type': 'call', 'children': ['234', '239']},{'id': '234', 'type': 'attribute', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'masked_where'},{'id': '239', 'type': 'argument_list', 'children': ['240', '246']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'isinf'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'minfield'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'plt'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'pcolormesh'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254', '255', '256']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'string', 'children': [], 'value': "'Spacing'"},{'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': 'plt'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': "'Shift'"},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'colorbar'},{'id': '278', 'type': 'argument_list', 'children': []},{'id': '279', 'type': 'if_statement', 'children': ['280', '291']},{'id': '280', 'type': 'boolean_operator', 'children': ['281', '286'], 'value': 'or'},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': '>'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '290'], 'value': '>'},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '290', 'type': 'integer', 'children': [], 'value': '1'},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'subplot'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'integer', 'children': [], 'value': '122'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'string', 'children': [], 'value': "'Filter values of best filter'"},{'id': '306', 'type': 'for_statement', 'children': ['307', '308', '313']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '308', 'type': 'list', 'children': ['309', '310', '311', '312'], 'value': "['j0', 'j1', 'sin', 'cos']"},{'id': '309', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '310', 'type': 'string', 'children': [], 'value': "'j1'"},{'id': '311', 'type': 'string', 'children': [], 'value': "'sin'"},{'id': '312', 'type': 'string', 'children': [], 'value': "'cos'"},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'if_statement', 'children': ['315', '320']},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '320', 'type': 'block', 'children': ['321', '361']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '326', 'type': 'argument_list', 'children': ['327', '335', '350', '351', '354']},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '347', 'type': 'argument_list', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '350', 'type': 'string', 'children': [], 'value': "'.-'"},{'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '353', 'type': 'float', 'children': [], 'value': '.5'},{'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '356', 'type': 'binary_operator', 'children': ['357', '360'], 'value': '+'},{'id': '357', 'type': 'binary_operator', 'children': ['358', '359'], 'value': '+'},{'id': '358', 'type': 'string', 'children': [], 'value': "'abs('"},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '360', 'type': 'string', 'children': [], 'value': "')'"},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '366', 'type': 'argument_list', 'children': ['367', '375', '386', '387', '390']},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '375', 'type': 'call', 'children': ['376', '379']},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'unary_operator', 'children': ['381'], 'value': '-'},{'id': '381', 'type': 'call', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '383', 'type': 'argument_list', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '386', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '387', 'type': 'keyword_argument', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '389', 'type': 'string', 'children': [], 'value': "'k'"},{'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '392', 'type': 'integer', 'children': [], 'value': '4'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '398', 'type': 'argument_list', 'children': ['399', '402', '403', '404', '407', '410']},{'id': '399', 'type': 'attribute', 'children': ['400', '401']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '402', 'type': 'integer', 'children': [], 'value': '0'},{'id': '403', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '404', 'type': 'keyword_argument', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '406', 'type': 'string', 'children': [], 'value': "'k'"},{'id': '407', 'type': 'keyword_argument', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'ms'},{'id': '409', 'type': 'integer', 'children': [], 'value': '4'},{'id': '410', 'type': 'keyword_argument', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '412', 'type': 'string', 'children': [], 'value': "'Neg. values'"},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'call', 'children': ['415', '418']},{'id': '415', 'type': 'attribute', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '418', 'type': 'argument_list', 'children': ['419']},{'id': '419', 'type': 'string', 'children': [], 'value': "'Base (log10)'"},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'call', 'children': ['422', '425']},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '425', 'type': 'argument_list', 'children': ['426']},{'id': '426', 'type': 'string', 'children': [], 'value': "'Abs(Amplitude) (log10)'"},{'id': '427', 'type': 'expression_statement', 'children': ['428']},{'id': '428', 'type': 'call', 'children': ['429', '432']},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'legend'},{'id': '432', 'type': 'argument_list', 'children': ['433']},{'id': '433', 'type': 'keyword_argument', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '435', 'type': 'string', 'children': [], 'value': "'best'"},{'id': '436', 'type': 'expression_statement', 'children': ['437']},{'id': '437', 'type': 'call', 'children': ['438', '447']},{'id': '438', 'type': 'attribute', 'children': ['439', '446']},{'id': '439', 'type': 'attribute', 'children': ['440', '445']},{'id': '440', 'type': 'call', 'children': ['441', '444']},{'id': '441', 'type': 'attribute', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'gcf'},{'id': '444', 'type': 'argument_list', 'children': []},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '447', 'type': 'argument_list', 'children': []},{'id': '448', 'type': 'expression_statement', 'children': ['449']},{'id': '449', 'type': 'call', 'children': ['450', '453']},{'id': '450', 'type': 'attribute', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '453', 'type': 'argument_list', 'children': []} | def plot_result(filt, full, prntres=True):
r
if not plt:
print(plt_msg)
return
if prntres:
print_result(filt, full)
spacing = full[2][0, :, 0]
shift = full[2][1, 0, :]
minfield = np.squeeze(full[3])
plt.figure("Brute force result", figsize=(9.5, 4.5))
plt.subplots_adjust(wspace=.4, bottom=0.2)
if spacing.size > 1 or shift.size > 1:
plt.subplot(121)
if full[4] == 0:
plt.title("Minimal recovered fields")
ylabel = 'Minimal recovered amplitude (log10)'
field = np.log10(minfield)
cmap = plt.cm.viridis
else:
plt.title("Maximum recovered r")
ylabel = 'Maximum recovered r'
field = 1/minfield
cmap = plt.cm.viridis_r
if shift.size == 1:
plt.plot(spacing, field)
plt.xlabel('Spacing')
plt.ylabel(ylabel)
elif spacing.size == 1:
plt.plot(shift, field)
plt.xlabel('Shift')
plt.ylabel(ylabel)
else:
field = np.ma.masked_where(np.isinf(minfield), field)
plt.pcolormesh(shift, spacing, field, cmap=cmap)
plt.ylabel('Spacing')
plt.xlabel('Shift')
plt.colorbar()
if spacing.size > 1 or shift.size > 1:
plt.subplot(122)
plt.title('Filter values of best filter')
for attr in ['j0', 'j1', 'sin', 'cos']:
if hasattr(filt, attr):
plt.plot(np.log10(filt.base),
np.log10(np.abs(getattr(filt, attr))), '.-', lw=.5,
label='abs('+attr+')')
plt.plot(np.log10(filt.base), np.log10(-getattr(filt, attr)), '.',
color='k', ms=4)
plt.plot(np.inf, 0, '.', color='k', ms=4, label='Neg. values')
plt.xlabel('Base (log10)')
plt.ylabel('Abs(Amplitude) (log10)')
plt.legend(loc='best')
plt.gcf().canvas.draw()
plt.show() |
{'id': '0', 'type': 'module', 'children': ['1', '10', '12', '21', '32', '122', '134', '143', '152', '163', '223', '372', '384']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_plot_transform_pairs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fCI'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '9', 'type': 'block', 'children': [], 'value': ''},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'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': 'plt'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sca'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'plt'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '31'], 'value': '+'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'},{'id': '29', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '31', 'type': 'string', 'children': [], 'value': "' lhs|'"},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fCI'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '42', '94']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '=='},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'string', 'children': [], 'value': "'j2'"},{'id': '42', 'type': 'block', 'children': ['43', '52', '73']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'plt'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '67', '70']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '69', 'type': 'integer', 'children': [], 'value': '2'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '72', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '88', '91']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'abs'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '90', 'type': 'integer', 'children': [], 'value': '2'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '93', 'type': 'string', 'children': [], 'value': "'j1'"},{'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': 'plt'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '114', '117']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'abs'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '116', 'type': 'integer', 'children': [], 'value': '2'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '122', 'type': 'if_statement', 'children': ['123', '126']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '!='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '125', 'type': 'string', 'children': [], 'value': "'fC'"},{'id': '126', 'type': 'block', 'children': ['127']},{'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': 'plt'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': "'l'"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'legend'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '142', 'type': 'string', 'children': [], 'value': "'best'"},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sca'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'plt'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '+'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '162', 'type': 'string', 'children': [], 'value': "' rhs|'"},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'fCI'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'if_statement', 'children': ['168', '171', '195']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': '=='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '170', 'type': 'string', 'children': [], 'value': "'fC'"},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179', '187', '190']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '189', 'type': 'integer', 'children': [], 'value': '2'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204', '215', '218']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '217', 'type': 'integer', 'children': [], 'value': '2'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '223', 'type': 'for_statement', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'fCI'},{'id': '226', 'type': 'block', 'children': ['227', '253', '265', '350']},{'id': '227', 'type': 'if_statement', 'children': ['228', '238', '245']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '234'], 'value': 'in'},{'id': '229', 'type': 'subscript', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '233', 'type': 'integer', 'children': [], 'value': '1'},{'id': '234', 'type': 'list', 'children': ['235', '236', '237'], 'value': "['0', '1', '2']"},{'id': '235', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '236', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '237', 'type': 'string', 'children': [], 'value': "'2'"},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'j0j1filt'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'else_clause', 'children': ['246']},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'sincosfilt'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '260'], 'value': '/'},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '260', 'type': 'subscript', 'children': ['261', '262', '264']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '262', 'type': 'slice', 'children': ['263']},{'id': '263', 'type': 'colon', 'children': []},{'id': '264', 'type': 'None', 'children': []},{'id': '265', 'type': 'if_statement', 'children': ['266', '271', '325']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '270'], 'value': '=='},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '270', 'type': 'string', 'children': [], 'value': "'j2'"},{'id': '271', 'type': 'block', 'children': ['272', '281', '299', '319']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'assignment', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'kr0'},{'id': '284', 'type': 'binary_operator', 'children': ['285', '298'], 'value': '/'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '289', 'type': 'argument_list', 'children': ['290', '293']},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '292', 'type': 'integer', 'children': [], 'value': '0'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '295', 'type': 'argument_list', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '297', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'kr1'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '316'], 'value': '/'},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '307', 'type': 'argument_list', 'children': ['308', '311']},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '310', 'type': 'integer', 'children': [], 'value': '1'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '313', 'type': 'argument_list', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '315', 'type': 'string', 'children': [], 'value': "'j1'"},{'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '**'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '318', 'type': 'integer', 'children': [], 'value': '2'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'kr'},{'id': '322', 'type': 'binary_operator', 'children': ['323', '324'], 'value': '+'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'kr0'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'kr1'},{'id': '325', 'type': 'else_clause', 'children': ['326']},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'kr'},{'id': '330', 'type': 'binary_operator', 'children': ['331', '349'], 'value': '/'},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '335', 'type': 'argument_list', 'children': ['336', '342']},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '344', 'type': 'argument_list', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'loglog'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357', '363', '364', '367']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '357', 'type': 'call', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'kr'},{'id': '363', 'type': 'string', 'children': [], 'value': "'-.'"},{'id': '364', 'type': 'keyword_argument', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'lw'},{'id': '366', 'type': 'integer', 'children': [], 'value': '2'},{'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'filt'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '372', 'type': 'if_statement', 'children': ['373', '376']},{'id': '373', 'type': 'comparison_operator', 'children': ['374', '375'], 'value': '!='},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'tit'},{'id': '375', 'type': 'string', 'children': [], 'value': "'fC'"},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'legend'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'keyword_argument', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '392', 'type': 'string', 'children': [], 'value': "'best'"} | def _plot_transform_pairs(fCI, r, k, axes, tit):
r
plt.sca(axes[0])
plt.title('|' + tit + ' lhs|')
for f in fCI:
if f.name == 'j2':
lhs = f.lhs(k)
plt.loglog(k, np.abs(lhs[0]), lw=2, label='j0')
plt.loglog(k, np.abs(lhs[1]), lw=2, label='j1')
else:
plt.loglog(k, np.abs(f.lhs(k)), lw=2, label=f.name)
if tit != 'fC':
plt.xlabel('l')
plt.legend(loc='best')
plt.sca(axes[1])
plt.title('|' + tit + ' rhs|')
for f in fCI:
if tit == 'fC':
plt.loglog(r, np.abs(f.rhs), lw=2, label=f.name)
else:
plt.loglog(r, np.abs(f.rhs(r)), lw=2, label=f.name)
for f in fCI:
if f.name[1] in ['0', '1', '2']:
filt = j0j1filt()
else:
filt = sincosfilt()
kk = filt.base/r[:, None]
if f.name == 'j2':
lhs = f.lhs(kk)
kr0 = np.dot(lhs[0], getattr(filt, 'j0'))/r
kr1 = np.dot(lhs[1], getattr(filt, 'j1'))/r**2
kr = kr0+kr1
else:
kr = np.dot(f.lhs(kk), getattr(filt, f.name))/r
plt.loglog(r, np.abs(kr), '-.', lw=2, label=filt.name)
if tit != 'fC':
plt.xlabel('r')
plt.legend(loc='best') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'empy_hankel'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18', '21', '24', '27', '30', '33']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'freqtime'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'verblhs'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'verbrhs'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'block', 'children': ['37', '39', '79', '110', '195', '235', '288']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'block', 'children': ['46', '50', '77']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'empy_hankel'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'freqtime'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'verblhs'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'verbrhs'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '82', 'type': 'dictionary', 'children': ['83', '89', '92', '95', '98', '101', '104', '107']},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'src'"},{'id': '85', 'type': 'list', 'children': ['86', '87', '88'], 'value': '[0, 0, zsrc]'},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'depth'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'res'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'aniso'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'aniso'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'epermH'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'epermH'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'epermV'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'epermV'},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'mpermH'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'mpermH'},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'mpermV'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'mpermV'},{'id': '110', 'type': 'if_statement', 'children': ['111', '114', '143', '162']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '=='},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '113', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '114', 'type': 'block', 'children': ['115', '121', '132']},{'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': 'model'},{'id': '119', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '120', 'type': 'integer', 'children': [], 'value': '11'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '/'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'integer', 'children': [], 'value': '2'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '/'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'integer', 'children': [], 'value': '2'},{'id': '143', 'type': 'elif_clause', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '=='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '146', 'type': 'string', 'children': [], 'value': "'j1'"},{'id': '147', 'type': 'block', 'children': ['148', '154', '158']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '152', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '153', 'type': 'integer', 'children': [], 'value': '31'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'elif_clause', 'children': ['163', '166']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '=='},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '165', 'type': 'string', 'children': [], 'value': "'j2'"},{'id': '166', 'type': 'block', 'children': ['167', '173', '184']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '171', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '172', 'type': 'integer', 'children': [], 'value': '12'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '/'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'integer', 'children': [], 'value': '2'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '/'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'integer', 'children': [], 'value': '2'},{'id': '195', 'type': 'function_definition', 'children': ['196', '197', '199']},{'id': '196', 'type': 'function_name', 'children': [], 'value': 'rhs'},{'id': '197', 'type': 'parameters', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '199', 'type': 'block', 'children': ['200', '233']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'dipole'},{'id': '205', 'type': 'argument_list', 'children': ['206', '216', '219', '222', '225', '228', '231']},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '208', 'type': 'list', 'children': ['209', '212', '215'], 'value': '[r*x, r*y, zrec]'},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '*'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '*'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ht'},{'id': '218', 'type': 'string', 'children': [], 'value': "'qwe'"},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'xdirect'},{'id': '221', 'type': 'True', 'children': []},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'verbrhs'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'htarg'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'freqtime'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'freqtime'},{'id': '231', 'type': 'dictionary_splat', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '235', 'type': 'function_definition', 'children': ['236', '237', '239']},{'id': '236', 'type': 'function_name', 'children': [], 'value': 'lhs'},{'id': '237', 'type': 'parameters', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '239', 'type': 'block', 'children': ['240', '265']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '245']},{'id': '242', 'type': 'pattern_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'lhs0'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'lhs1'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'dipole_k'},{'id': '247', 'type': 'argument_list', 'children': ['248', '254', '257', '260', '263']},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '250', 'type': 'list', 'children': ['251', '252', '253'], 'value': '[x, y, zrec]'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'verblhs'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'freqtime'},{'id': '263', 'type': 'dictionary_splat', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '265', 'type': 'if_statement', 'children': ['266', '269', '272', '279']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '268'], 'value': '=='},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '268', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'return_statement', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'lhs0'},{'id': '272', 'type': 'elif_clause', 'children': ['273', '276']},{'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': '=='},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '275', 'type': 'string', 'children': [], 'value': "'j1'"},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'return_statement', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'lhs1'},{'id': '279', 'type': 'elif_clause', 'children': ['280', '283']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '282', 'type': 'string', 'children': [], 'value': "'j2'"},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'return_statement', 'children': ['285']},{'id': '285', 'type': 'tuple', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'lhs0'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'lhs1'},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'Ghosh'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'rhs'} | def empy_hankel(ftype, zsrc, zrec, res, freqtime, depth=None, aniso=None,
epermH=None, epermV=None, mpermH=None, mpermV=None,
htarg=None, verblhs=0, verbrhs=0):
r
if isinstance(ftype, list):
out = []
for f in ftype:
out.append(empy_hankel(f, zsrc, zrec, res, freqtime, depth, aniso,
epermH, epermV, mpermH, mpermV, htarg,
verblhs, verbrhs))
return out
model = {'src': [0, 0, zsrc],
'depth': depth,
'res': res,
'aniso': aniso,
'epermH': epermH,
'epermV': epermV,
'mpermH': mpermH,
'mpermV': mpermV}
if ftype == 'j0':
model['ab'] = 11
x = 1/np.sqrt(2)
y = 1/np.sqrt(2)
elif ftype == 'j1':
model['ab'] = 31
x = 1
y = 0
elif ftype == 'j2':
model['ab'] = 12
x = 1/np.sqrt(2)
y = 1/np.sqrt(2)
def rhs(r):
out = dipole(rec=[r*x, r*y, zrec], ht='qwe', xdirect=True,
verb=verbrhs, htarg=htarg, freqtime=freqtime, **model)
return out
def lhs(k):
lhs0, lhs1 = dipole_k(rec=[x, y, zrec], wavenumber=k, verb=verblhs,
freq=freqtime, **model)
if ftype == 'j0':
return lhs0
elif ftype == 'j1':
return lhs1
elif ftype == 'j2':
return (lhs0, lhs1)
return Ghosh(ftype, lhs, rhs) |
{'id': '0', 'type': 'module', 'children': ['1', '8', '10', '16', '31', '44', '56', '370', '382']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_min_val'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'spaceshift'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '7', 'type': 'block', 'children': [], 'value': ''},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '15']},{'id': '12', 'type': 'pattern_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'spaceshift'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '30']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fI'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fC'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'r_def'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reim'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cvar'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dlf'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_calculate_filter'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41', '42', '43']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fI'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'r_def'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'reim'},{'id': '43', 'type': 'string', 'children': [], 'value': "'filt'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '/'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'dlf'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '51', 'type': 'subscript', 'children': ['52', '53', '55']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '53', 'type': 'slice', 'children': ['54']},{'id': '54', 'type': 'colon', 'children': []},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'for_statement', 'children': ['57', '60', '64']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fC'},{'id': '64', 'type': 'block', 'children': ['65', '74', '145', '163', '176', '287', '313', '353']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '74', 'type': 'if_statement', 'children': ['75', '80', '125']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '=='},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '79', 'type': 'string', 'children': [], 'value': "'j2'"},{'id': '80', 'type': 'block', 'children': ['81', '99', '119']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'rhs0'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '98'], 'value': '/'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dlf'},{'id': '97', 'type': 'string', 'children': [], 'value': "'j0'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rhs1'},{'id': '102', 'type': 'binary_operator', 'children': ['103', '116'], 'value': '/'},{'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': 'dot'},{'id': '107', 'type': 'argument_list', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dlf'},{'id': '115', 'type': 'string', 'children': [], 'value': "'j1'"},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '**'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '+'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rhs0'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'rhs1'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '144'], 'value': '/'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lhs'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'dlf'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'rel_error'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '160'], 'value': '/'},{'id': '154', 'type': '()', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '166', 'type': 'subscript', 'children': ['167', '175']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '>'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'rel_error'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'if_statement', 'children': ['177', '197', '202', '246']},{'id': '177', 'type': 'boolean_operator', 'children': ['178', '186'], 'value': 'or'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': '=='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'elif_clause', 'children': ['203', '208']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': '=='},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'block', 'children': ['209', '217']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '216'], 'value': '-'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'if_statement', 'children': ['218', '227']},{'id': '218', 'type': 'boolean_operator', 'children': ['219', '222'], 'value': 'and'},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': '>'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '=='},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '225', 'type': 'string', 'children': [], 'value': "'warn-r'"},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'block', 'children': ['228', '240']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'binary_operator', 'children': ['233', '239'], 'value': '+'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '+'},{'id': '234', 'type': 'string', 'children': [], 'value': "'* WARNING :: all data have error < '"},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '239', 'type': 'string', 'children': [], 'value': "'; choose larger r or set error-level higher.'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '245']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '244', 'type': 'string', 'children': [], 'value': "'warn-r'"},{'id': '245', 'type': 'integer', 'children': [], 'value': '1'},{'id': '246', 'type': 'else_clause', 'children': ['247']},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'if_statement', 'children': ['249', '254', '270']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '253'], 'value': '>'},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '253', 'type': 'integer', 'children': [], 'value': '4'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'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': 'max'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'list', 'children': ['264', '265'], 'value': '[0, imin0[4]-5]'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'binary_operator', 'children': ['266', '269'], 'value': '-'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '268', 'type': 'integer', 'children': [], 'value': '4'},{'id': '269', 'type': 'integer', 'children': [], 'value': '5'},{'id': '270', 'type': 'else_clause', 'children': ['271']},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '275', 'type': 'call', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'list', 'children': ['281', '282'], 'value': '[0, imin0[0]-1]'},{'id': '281', 'type': 'integer', 'children': [], 'value': '0'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '286'], 'value': '-'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '285', 'type': 'integer', 'children': [], 'value': '0'},{'id': '286', 'type': 'integer', 'children': [], 'value': '1'},{'id': '287', 'type': 'if_statement', 'children': ['288', '291', '303']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '=='},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'cvar'},{'id': '290', 'type': 'string', 'children': [], 'value': "'amp'"},{'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': 'min_val0'},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '303', 'type': 'else_clause', 'children': ['304']},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'min_val0'},{'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '/'},{'id': '309', 'type': 'integer', 'children': [], 'value': '1'},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '313', 'type': 'if_statement', 'children': ['314', '317', '332']},{'id': '314', 'type': 'comparison_operator', 'children': ['315', '316'], 'value': '=='},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '316', 'type': 'integer', 'children': [], 'value': '0'},{'id': '317', 'type': 'block', 'children': ['318', '325']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'imin'},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'assignment', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'min_val'},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'min_val0'},{'id': '332', 'type': 'else_clause', 'children': ['333']},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'if_statement', 'children': ['335', '338']},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': '>'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'min_val0'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'min_val'},{'id': '338', 'type': 'block', 'children': ['339', '346']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'assignment', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'min_val'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'min_val0'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'imin'},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '353', 'type': 'if_statement', 'children': ['354', '357']},{'id': '354', 'type': 'comparison_operator', 'children': ['355', '356'], 'value': '>'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '356', 'type': 'integer', 'children': [], 'value': '2'},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': '_plot_inversion'},{'id': '361', 'type': 'argument_list', 'children': ['362', '363', '364', '365', '366', '367', '368', '369']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'rhs'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'imin0'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'spacing'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'shift'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'cvar'},{'id': '370', 'type': 'if_statement', 'children': ['371', '374']},{'id': '371', 'type': 'comparison_operator', 'children': ['372', '373'], 'value': '>'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'verb'},{'id': '373', 'type': 'integer', 'children': [], 'value': '1'},{'id': '374', 'type': 'block', 'children': ['375']},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'assignment', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': '_print_count'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '382', 'type': 'return_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '387', 'type': 'argument_list', 'children': ['388', '391', '394']},{'id': '388', 'type': 'comparison_operator', 'children': ['389', '390'], 'value': '=='},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'imin'},{'id': '390', 'type': 'integer', 'children': [], 'value': '0'},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'min_val'} | def _get_min_val(spaceshift, *params):
r
spacing, shift = spaceshift
n, fI, fC, r, r_def, error, reim, cvar, verb, plot, log = params
dlf = _calculate_filter(n, spacing, shift, fI, r_def, reim, 'filt')
k = dlf.base/r[:, None]
for i, f in enumerate(fC):
lhs = f.lhs(k)
if f.name == 'j2':
rhs0 = np.dot(lhs[0], getattr(dlf, 'j0'))/r
rhs1 = np.dot(lhs[1], getattr(dlf, 'j1'))/r**2
rhs = rhs0 + rhs1
else:
rhs = np.dot(lhs, getattr(dlf, f.name))/r
rel_error = np.abs((rhs - f.rhs)/f.rhs)
imin0 = np.where(rel_error > error)[0]
if np.all(rhs == 0) or np.all(np.isnan(rhs)):
imin0 = 0
elif imin0.size == 0:
imin0 = rhs.size-1
if verb > 0 and log['warn-r'] == 0:
print('* WARNING :: all data have error < ' + str(error) +
'; choose larger r or set error-level higher.')
log['warn-r'] = 1
else:
if imin0.size > 4:
imin0 = np.max([0, imin0[4]-5])
else:
imin0 = np.max([0, imin0[0]-1])
if cvar == 'amp':
min_val0 = np.abs(rhs[imin0])
else:
min_val0 = 1/r[imin0]
if i == 0:
imin = dc(imin0)
min_val = dc(min_val0)
else:
if min_val0 > min_val:
min_val = dc(min_val0)
imin = dc(imin0)
if plot > 2:
_plot_inversion(f, rhs, r, k, imin0, spacing, shift, cvar)
if verb > 1:
log = _print_count(log)
return np.where(imin == 0, np.inf, min_val) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wavenumber'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'xdirect'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '19', 'type': 'block', 'children': ['20', '22', '45', '49', '53', '57', '71', '85', '219']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'PTM'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'PTE'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'greenfct'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'xdirect'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Ptot'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '65'], 'value': '/'},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'PTM'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'PTE'},{'id': '65', 'type': '()', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '*'},{'id': '67', 'type': 'integer', 'children': [], 'value': '4'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '71', 'type': 'if_statement', 'children': ['72', '73', '79']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '77', 'type': 'unary_operator', 'children': ['78'], 'value': '-'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'else_clause', 'children': ['80']},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'if_statement', 'children': ['86', '97', '166', '201']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'in'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '88', 'type': 'list', 'children': ['89', '90', '91', '92', '93', '94', '95', '96'], 'value': '[11, 12, 21, 22, 14, 24, 15, 25]'},{'id': '89', 'type': 'integer', 'children': [], 'value': '11'},{'id': '90', 'type': 'integer', 'children': [], 'value': '12'},{'id': '91', 'type': 'integer', 'children': [], 'value': '21'},{'id': '92', 'type': 'integer', 'children': [], 'value': '22'},{'id': '93', 'type': 'integer', 'children': [], 'value': '14'},{'id': '94', 'type': 'integer', 'children': [], 'value': '24'},{'id': '95', 'type': 'integer', 'children': [], 'value': '15'},{'id': '96', 'type': 'integer', 'children': [], 'value': '25'},{'id': '97', 'type': 'block', 'children': ['98', '110', '120', '127']},{'id': '98', 'type': 'if_statement', 'children': ['99', '104']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '101', 'type': 'list', 'children': ['102', '103'], 'value': '[14, 22]'},{'id': '102', 'type': 'integer', 'children': [], 'value': '14'},{'id': '103', 'type': 'integer', 'children': [], 'value': '22'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'augmented_assignment', 'children': ['107', '108'], 'value': '*='},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '108', 'type': 'unary_operator', 'children': ['109'], 'value': '-'},{'id': '109', 'type': 'integer', 'children': [], 'value': '1'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '119'], 'value': '*'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '*'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '/'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '117', 'type': 'integer', 'children': [], 'value': '2'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'Ptot'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '126'], 'value': '*'},{'id': '124', 'type': 'unary_operator', 'children': ['125'], 'value': '-'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Ptot'},{'id': '127', 'type': 'if_statement', 'children': ['128', '135']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'in'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '130', 'type': 'list', 'children': ['131', '132', '133', '134'], 'value': '[11, 22, 24, 15]'},{'id': '131', 'type': 'integer', 'children': [], 'value': '11'},{'id': '132', 'type': 'integer', 'children': [], 'value': '22'},{'id': '133', 'type': 'integer', 'children': [], 'value': '24'},{'id': '134', 'type': 'integer', 'children': [], 'value': '15'},{'id': '135', 'type': 'block', 'children': ['136', '148']},{'id': '136', 'type': 'if_statement', 'children': ['137', '142']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '139', 'type': 'list', 'children': ['140', '141'], 'value': '[22, 24]'},{'id': '140', 'type': 'integer', 'children': [], 'value': '22'},{'id': '141', 'type': 'integer', 'children': [], 'value': '24'},{'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': 'sign'},{'id': '146', 'type': 'unary_operator', 'children': ['147'], 'value': '-'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '165'], 'value': '*'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '159'], 'value': '/'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '*'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '-'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'PTM'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'PTE'},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '*'},{'id': '161', 'type': 'integer', 'children': [], 'value': '8'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pi'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '166', 'type': 'elif_clause', 'children': ['167', '178']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'in'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '169', 'type': 'list', 'children': ['170', '171', '172', '173', '174', '175', '176', '177'], 'value': '[13, 23, 31, 32, 34, 35, 16, 26]'},{'id': '170', 'type': 'integer', 'children': [], 'value': '13'},{'id': '171', 'type': 'integer', 'children': [], 'value': '23'},{'id': '172', 'type': 'integer', 'children': [], 'value': '31'},{'id': '173', 'type': 'integer', 'children': [], 'value': '32'},{'id': '174', 'type': 'integer', 'children': [], 'value': '34'},{'id': '175', 'type': 'integer', 'children': [], 'value': '35'},{'id': '176', 'type': 'integer', 'children': [], 'value': '16'},{'id': '177', 'type': 'integer', 'children': [], 'value': '26'},{'id': '178', 'type': 'block', 'children': ['179', '189']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '188'], 'value': '*'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '*'},{'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '*'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'Ptot'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '189', 'type': 'if_statement', 'children': ['190', '195']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'in'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '192', 'type': 'list', 'children': ['193', '194'], 'value': '[34, 26]'},{'id': '193', 'type': 'integer', 'children': [], 'value': '34'},{'id': '194', 'type': 'integer', 'children': [], 'value': '26'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '*='},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '199', 'type': 'unary_operator', 'children': ['200'], 'value': '-'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'elif_clause', 'children': ['202', '206']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'in'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '204', 'type': 'list', 'children': ['205'], 'value': '[33, ]'},{'id': '205', 'type': 'integer', 'children': [], 'value': '33'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '218'], 'value': '*'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '217'], 'value': '*'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '216'], 'value': '*'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '*'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Ptot'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'lambd'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'expression_list', 'children': ['221', '222', '223']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'PJ0b'} | def wavenumber(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH, zetaV, lambd,
ab, xdirect, msrc, mrec, use_ne_eval):
r
PTM, PTE = greenfct(zsrc, zrec, lsrc, lrec, depth, etaH, etaV, zetaH,
zetaV, lambd, ab, xdirect, msrc, mrec, use_ne_eval)
PJ0 = None
PJ1 = None
PJ0b = None
Ptot = (PTM + PTE)/(4*np.pi)
if mrec:
sign = -1
else:
sign = 1
if ab in [11, 12, 21, 22, 14, 24, 15, 25]:
if ab in [14, 22]:
sign *= -1
PJ0b = sign/2*Ptot*lambd
PJ1 = -sign*Ptot
if ab in [11, 22, 24, 15]:
if ab in [22, 24]:
sign *= -1
PJ0 = sign*(PTM - PTE)/(8*np.pi)*lambd
elif ab in [13, 23, 31, 32, 34, 35, 16, 26]:
PJ1 = sign*Ptot*lambd*lambd
if ab in [34, 26]:
PJ1 *= -1
elif ab in [33, ]:
PJ0 = sign*Ptot*lambd*lambd*lambd
return PJ0, PJ1, PJ0b |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reflections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'e_zH'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '10', 'type': 'block', 'children': ['11', '13', '407']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '15', 'type': 'list', 'children': ['16', '17'], 'value': '[True, False]'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '102', '115', '131', '140', '175', '379', '394']},{'id': '19', 'type': 'if_statement', 'children': ['20', '21', '65']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '21', 'type': 'block', 'children': ['22', '26', '48', '57']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'layer_count'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '33', 'type': 'argument_list', 'children': ['34', '39', '46']},{'id': '34', 'type': 'binary_operator', 'children': ['35', '38'], 'value': '-'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '38', 'type': 'integer', 'children': [], 'value': '2'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '45'], 'value': '-'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'izout'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'minmax'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67', '72', '89', '93']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '70', 'type': 'unary_operator', 'children': ['71'], 'value': '-'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'layer_count'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81', '88']},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '87'], 'value': '+'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'izout'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'minmax'},{'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '-'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'shiftplus'},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '113'], 'value': 'and'},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'and'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '<'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'not_operator', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'shiftminus'},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '130'], 'value': 'and'},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '>'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '=='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '-'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '131', 'type': 'if_statement', 'children': ['132', '135']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '134'], 'value': 'or'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'shiftplus'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'shiftminus'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '-='},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'izout'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Ref'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '147', 'type': 'argument_list', 'children': ['148', '172']},{'id': '148', 'type': 'tuple', 'children': ['149', '154', '159', '167']},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'subscript', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '166'], 'value': '+'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '-'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'subscript', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '171', 'type': 'integer', 'children': [], 'value': '3'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '175', 'type': 'for_statement', 'children': ['176', '177', '178']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'layer_count'},{'id': '178', 'type': 'block', 'children': ['179', '191', '203', '213', '227', '267', '349']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'e_zHa'},{'id': '182', 'type': 'subscript', 'children': ['183', '184', '186', '187', '190']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'e_zH'},{'id': '184', 'type': 'slice', 'children': ['185']},{'id': '185', 'type': 'colon', 'children': []},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '+'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '190', 'type': 'None', 'children': []},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'Gama'},{'id': '194', 'type': 'subscript', 'children': ['195', '196', '198', '200', '201']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '196', 'type': 'slice', 'children': ['197']},{'id': '197', 'type': 'colon', 'children': []},{'id': '198', 'type': 'slice', 'children': ['199']},{'id': '199', 'type': 'colon', 'children': []},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '201', 'type': 'slice', 'children': ['202']},{'id': '202', 'type': 'colon', 'children': []},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'e_zHb'},{'id': '206', 'type': 'subscript', 'children': ['207', '208', '210', '211', '212']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'e_zH'},{'id': '208', 'type': 'slice', 'children': ['209']},{'id': '209', 'type': 'colon', 'children': []},{'id': '210', 'type': 'None', 'children': []},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Gamb'},{'id': '216', 'type': 'subscript', 'children': ['217', '218', '220', '222', '225']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'Gam'},{'id': '218', 'type': 'slice', 'children': ['219']},{'id': '219', 'type': 'colon', 'children': []},{'id': '220', 'type': 'slice', 'children': ['221']},{'id': '221', 'type': 'colon', 'children': []},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '+'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '225', 'type': 'slice', 'children': ['226']},{'id': '226', 'type': 'colon', 'children': []},{'id': '227', 'type': 'if_statement', 'children': ['228', '229', '241']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '229', 'type': 'block', 'children': ['230', '234']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'rlocstr'},{'id': '233', 'type': 'string', 'children': [], 'value': '"(e_zHa*Gama - e_zHb*Gamb)/(e_zHa*Gama + e_zHb*Gamb)"'},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'rloc'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'rlocstr'},{'id': '241', 'type': 'else_clause', 'children': ['242']},{'id': '242', 'type': 'block', 'children': ['243', '249', '255']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'rloca'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '*'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'e_zHa'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'Gama'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'rlocb'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '*'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'e_zHb'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'Gamb'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'rloc'},{'id': '258', 'type': 'binary_operator', 'children': ['259', '263'], 'value': '/'},{'id': '259', 'type': '()', 'children': ['260']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '-'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'rloca'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'rlocb'},{'id': '263', 'type': '()', 'children': ['264']},{'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '+'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'rloca'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'rlocb'},{'id': '267', 'type': 'if_statement', 'children': ['268', '273', '282']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': '=='},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'layer_count'},{'id': '272', 'type': 'integer', 'children': [], 'value': '0'},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'rloc'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '281', 'type': 'argument_list', 'children': []},{'id': '282', 'type': 'else_clause', 'children': ['283']},{'id': '283', 'type': 'block', 'children': ['284', '300']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'ddepth'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '295'], 'value': '-'},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '290', 'type': 'binary_operator', 'children': ['291', '294'], 'value': '+'},{'id': '291', 'type': 'binary_operator', 'children': ['292', '293'], 'value': '+'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '293', 'type': 'integer', 'children': [], 'value': '1'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '300', 'type': 'if_statement', 'children': ['301', '302', '317']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '302', 'type': 'block', 'children': ['303', '310']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'string', 'children': [], 'value': '"tRef*exp(-2*Gamb*ddepth)"'},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'string', 'children': [], 'value': '"(rloc + term)/(1 + rloc*term)"'},{'id': '317', 'type': 'else_clause', 'children': ['318']},{'id': '318', 'type': 'block', 'children': ['319', '335']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '322', 'type': 'binary_operator', 'children': ['323', '324'], 'value': '*'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'binary_operator', 'children': ['330', '334'], 'value': '*'},{'id': '330', 'type': 'binary_operator', 'children': ['331', '333'], 'value': '*'},{'id': '331', 'type': 'unary_operator', 'children': ['332'], 'value': '-'},{'id': '332', 'type': 'integer', 'children': [], 'value': '2'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'Gamb'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'ddepth'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '338', 'type': 'binary_operator', 'children': ['339', '343'], 'value': '/'},{'id': '339', 'type': '()', 'children': ['340']},{'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '+'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'rloc'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '343', 'type': '()', 'children': ['344']},{'id': '344', 'type': 'binary_operator', 'children': ['345', '346'], 'value': '+'},{'id': '345', 'type': 'integer', 'children': [], 'value': '1'},{'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '*'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'rloc'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '349', 'type': 'if_statement', 'children': ['350', '359']},{'id': '350', 'type': 'boolean_operator', 'children': ['351', '354'], 'value': 'and'},{'id': '351', 'type': 'comparison_operator', 'children': ['352', '353'], 'value': '!='},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '354', 'type': 'comparison_operator', 'children': ['355', '358'], 'value': '<='},{'id': '355', 'type': 'binary_operator', 'children': ['356', '357'], 'value': '*'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'iz'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'minmax'},{'id': '359', 'type': 'block', 'children': ['360', '375']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'assignment', 'children': ['362', '371']},{'id': '362', 'type': 'subscript', 'children': ['363', '364', '366', '368', '369']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'Ref'},{'id': '364', 'type': 'slice', 'children': ['365']},{'id': '365', 'type': 'colon', 'children': []},{'id': '366', 'type': 'slice', 'children': ['367']},{'id': '367', 'type': 'colon', 'children': []},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'izout'},{'id': '369', 'type': 'slice', 'children': ['370']},{'id': '370', 'type': 'colon', 'children': []},{'id': '371', 'type': 'subscript', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '373', 'type': 'slice', 'children': ['374']},{'id': '374', 'type': 'colon', 'children': []},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'augmented_assignment', 'children': ['377', '378'], 'value': '-='},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'izout'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'pm'},{'id': '379', 'type': 'if_statement', 'children': ['380', '389']},{'id': '380', 'type': 'boolean_operator', 'children': ['381', '384'], 'value': 'and'},{'id': '381', 'type': 'comparison_operator', 'children': ['382', '383'], 'value': '=='},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '384', 'type': 'comparison_operator', 'children': ['385', '388'], 'value': '>'},{'id': '385', 'type': 'attribute', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'layer_count'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '388', 'type': 'integer', 'children': [], 'value': '0'},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'assignment', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'Ref'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'tRef'},{'id': '394', 'type': 'if_statement', 'children': ['395', '396', '401']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'plus'},{'id': '396', 'type': 'block', 'children': ['397']},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'assignment', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'Rm'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'Ref'},{'id': '401', 'type': 'else_clause', 'children': ['402']},{'id': '402', 'type': 'block', 'children': ['403']},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'assignment', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'Rp'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'Ref'},{'id': '407', 'type': 'return_statement', 'children': ['408']},{'id': '408', 'type': 'expression_list', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'Rm'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'Rp'} | def reflections(depth, e_zH, Gam, lrec, lsrc, use_ne_eval):
r
for plus in [True, False]:
if plus:
pm = 1
layer_count = np.arange(depth.size-2, min(lrec, lsrc)-1, -1)
izout = abs(lsrc-lrec)
minmax = max(lrec, lsrc)
else:
pm = -1
layer_count = np.arange(1, max(lrec, lsrc)+1, 1)
izout = 0
minmax = -min(lrec, lsrc)
shiftplus = lrec < lsrc and lrec == 0 and not plus
shiftminus = lrec > lsrc and lrec == depth.size-1 and plus
if shiftplus or shiftminus:
izout -= pm
Ref = np.zeros((Gam.shape[0], Gam.shape[1], abs(lsrc-lrec)+1,
Gam.shape[3]), dtype=complex)
for iz in layer_count:
e_zHa = e_zH[:, None, iz+pm, None]
Gama = Gam[:, :, iz, :]
e_zHb = e_zH[:, None, iz, None]
Gamb = Gam[:, :, iz+pm, :]
if use_ne_eval:
rlocstr = "(e_zHa*Gama - e_zHb*Gamb)/(e_zHa*Gama + e_zHb*Gamb)"
rloc = use_ne_eval(rlocstr)
else:
rloca = e_zHa*Gama
rlocb = e_zHb*Gamb
rloc = (rloca - rlocb)/(rloca + rlocb)
if iz == layer_count[0]:
tRef = rloc.copy()
else:
ddepth = depth[iz+1+pm]-depth[iz+pm]
if use_ne_eval:
term = use_ne_eval("tRef*exp(-2*Gamb*ddepth)")
tRef = use_ne_eval("(rloc + term)/(1 + rloc*term)")
else:
term = tRef*np.exp(-2*Gamb*ddepth)
tRef = (rloc + term)/(1 + rloc*term)
if lrec != lsrc and pm*iz <= minmax:
Ref[:, :, izout, :] = tRef[:]
izout -= pm
if lsrc == lrec and layer_count.size > 0:
Ref = tRef
if plus:
Rm = Ref
else:
Rp = Ref
return Rm, Rp |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hquad'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'xdirect'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'quadargs'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '21', 'type': 'block', 'children': ['22', '24', '34', '43', '52', '70', '101', '146', '191', '236', '250', '254', '273', '310']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '33']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28', '29', '30', '31', '32']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'rtol'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'atol'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pts_per_dec'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'quadargs'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'la'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lb'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'log10'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'logspace'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'la'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lb'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '+'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '68'], 'value': '*'},{'id': '64', 'type': '()', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '-'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'lb'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'la'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pts_per_dec'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '76']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kernel'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'wavenumber'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '96', '97', '98', '99', '100']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'zsrc'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'zrec'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lsrc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'lrec'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'etaH'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'etaV'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'zetaH'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'zetaV'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'xdirect'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'msrc'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'mrec'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'use_ne_eval'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105', '136']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'block', 'children': ['106', '121']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '111', 'type': 'argument_list', 'children': ['112', '118']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'real'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sPJ0i'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '126', 'type': 'argument_list', 'children': ['127', '133']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'PJ0'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'imag'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138', '142']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '141', 'type': 'None', 'children': []},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sPJ0i'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'if_statement', 'children': ['147', '150', '181']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'block', 'children': ['151', '166']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '156', 'type': 'argument_list', 'children': ['157', '163']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'real'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sPJ1i'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '171', 'type': 'argument_list', 'children': ['172', '178']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'PJ1'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'imag'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183', '187']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '186', 'type': 'None', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'sPJ1i'},{'id': '190', 'type': 'None', 'children': []},{'id': '191', 'type': 'if_statement', 'children': ['192', '195', '226']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'block', 'children': ['196', '211']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '201', 'type': 'argument_list', 'children': ['202', '208']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'real'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sPJ0bi'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'iuSpline'},{'id': '216', 'type': 'argument_list', 'children': ['217', '223']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ilambd'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'PJ0b'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'imag'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228', '232']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '231', 'type': 'None', 'children': []},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sPJ0bi'},{'id': '235', 'type': 'None', 'children': []},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'fEM'},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '243', 'type': 'argument_list', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'complex'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '253', 'type': 'True', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '257', 'type': 'dictionary', 'children': ['258', '261', '264', '267', '270']},{'id': '258', 'type': 'pair', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '264', 'type': 'pair', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': "'epsabs'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'atol'},{'id': '267', 'type': 'pair', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'epsrel'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'rtol'},{'id': '270', 'type': 'pair', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '273', 'type': 'for_statement', 'children': ['274', '275', '281']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '281', 'type': 'block', 'children': ['282', '306']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '289']},{'id': '284', 'type': 'pattern_list', 'children': ['285', '288']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'fEM'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'tc'},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '295', '296', '297', '298', '299', '302', '305']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'sPJ0i'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sPJ1i'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'sPJ0bi'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '302', 'type': 'subscript', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'augmented_assignment', 'children': ['308', '309'], 'value': '*='},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'tc'},{'id': '310', 'type': 'return_statement', 'children': ['311']},{'id': '311', 'type': 'expression_list', 'children': ['312', '313', '314']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'fEM'},{'id': '313', 'type': 'integer', 'children': [], 'value': '1'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'conv'} | def hquad(zsrc, zrec, lsrc, lrec, off, factAng, depth, ab, etaH, etaV, zetaH,
zetaV, xdirect, quadargs, use_ne_eval, msrc, mrec):
r
rtol, atol, limit, a, b, pts_per_dec = quadargs
la = np.log10(a)
lb = np.log10(b)
ilambd = np.logspace(la, lb, (lb-la)*pts_per_dec + 1)
PJ0, PJ1, PJ0b = kernel.wavenumber(zsrc, zrec, lsrc, lrec, depth, etaH,
etaV, zetaH, zetaV,
np.atleast_2d(ilambd), ab, xdirect,
msrc, mrec, use_ne_eval)
if PJ0 is not None:
sPJ0r = iuSpline(np.log(ilambd), PJ0.real)
sPJ0i = iuSpline(np.log(ilambd), PJ0.imag)
else:
sPJ0r = None
sPJ0i = None
if PJ1 is not None:
sPJ1r = iuSpline(np.log(ilambd), PJ1.real)
sPJ1i = iuSpline(np.log(ilambd), PJ1.imag)
else:
sPJ1r = None
sPJ1i = None
if PJ0b is not None:
sPJ0br = iuSpline(np.log(ilambd), PJ0b.real)
sPJ0bi = iuSpline(np.log(ilambd), PJ0b.imag)
else:
sPJ0br = None
sPJ0bi = None
fEM = np.zeros(off.size, dtype=complex)
conv = True
iinp = {'a': a, 'b': b, 'epsabs': atol, 'epsrel': rtol, 'limit': limit}
for i in range(off.size):
fEM[i], tc = quad(sPJ0r, sPJ0i, sPJ1r, sPJ1i, sPJ0br, sPJ0bi, ab,
off[i], factAng[i], iinp)
conv *= tc
return fEM, 1, conv |
{'id': '0', 'type': 'module', 'children': ['1', '24', '26', '45', '54', '56', '70', '87', '98', '106', '108', '129', '133', '144', '150', '217', '288', '357']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'quad'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sPJ0i'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sPJ1i'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sPJ0bi'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '14', 'type': 'block', 'children': ['15', '17']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '23']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'quad_PJ0'},{'id': '19', 'type': 'parameters', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sPJ0'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '23', 'type': 'block', 'children': [], 'value': ''},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '37'], 'value': '*'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sPJ0'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'special'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'j0'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '*'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '45', 'type': 'function_definition', 'children': ['46', '47', '53']},{'id': '46', 'type': 'function_name', 'children': [], 'value': 'quad_PJ1'},{'id': '47', 'type': 'parameters', 'children': ['48', '49', '50', '51', '52']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sPJ1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kang'},{'id': '53', 'type': 'block', 'children': [], 'value': ''},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tP1'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '*'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'kang'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sPJ1'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '70', 'type': 'if_statement', 'children': ['71', '82']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '73', 'type': 'list', 'children': ['74', '75', '76', '77', '78', '79', '80', '81'], 'value': '[11, 12, 21, 22, 14, 24, 15, 25]'},{'id': '74', 'type': 'integer', 'children': [], 'value': '11'},{'id': '75', 'type': 'integer', 'children': [], 'value': '12'},{'id': '76', 'type': 'integer', 'children': [], 'value': '21'},{'id': '77', 'type': 'integer', 'children': [], 'value': '22'},{'id': '78', 'type': 'integer', 'children': [], 'value': '14'},{'id': '79', 'type': 'integer', 'children': [], 'value': '24'},{'id': '80', 'type': 'integer', 'children': [], 'value': '15'},{'id': '81', 'type': 'integer', 'children': [], 'value': '25'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'augmented_assignment', 'children': ['85', '86'], 'value': '/='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tP1'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'tP1'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'special'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'j1'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '*'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '105']},{'id': '99', 'type': 'function_name', 'children': [], 'value': 'quad_PJ0b'},{'id': '100', 'type': 'parameters', 'children': ['101', '102', '103', '104']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sPJ0b'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'kang'},{'id': '105', 'type': 'block', 'children': [], 'value': ''},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'binary_operator', 'children': ['110', '121'], 'value': '*'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '*'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kang'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sPJ0b'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'special'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'j0'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '*'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'koff'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'klambd'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '132', 'type': 'True', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'},{'id': '142', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '143', 'type': 'float', 'children': [], 'value': '0.0j'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '148', 'type': 'string', 'children': [], 'value': "'full_output'"},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155', '171', '187', '199']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '169']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'quad_PJ0'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '166', 'type': 'tuple', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sPJ0r'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '169', 'type': 'dictionary_splat', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '185']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'quad_PJ0'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '182', 'type': 'tuple', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sPJ0i'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '185', 'type': 'dictionary_splat', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'augmented_assignment', 'children': ['189', '190'], 'value': '+='},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '194'], 'value': '+'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '*'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1j'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '198', 'type': 'integer', 'children': [], 'value': '0'},{'id': '199', 'type': 'if_statement', 'children': ['200', '212']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '211'], 'value': '>'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '207'], 'value': 'or'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '211', 'type': 'integer', 'children': [], 'value': '3'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '216', 'type': 'False', 'children': []},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'is'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'block', 'children': ['222', '240', '258', '270']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231', '238']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'quad_PJ1'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '233', 'type': 'tuple', 'children': ['234', '235', '236', '237']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sPJ1r'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '238', 'type': 'dictionary_splat', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249', '256']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'quad_PJ1'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '251', 'type': 'tuple', 'children': ['252', '253', '254', '255']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'sPJ1i'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '256', 'type': 'dictionary_splat', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'augmented_assignment', 'children': ['260', '261'], 'value': '+='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '261', 'type': 'binary_operator', 'children': ['262', '265'], 'value': '+'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '*'},{'id': '266', 'type': 'integer', 'children': [], 'value': '1j'},{'id': '267', 'type': 'subscript', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'if_statement', 'children': ['271', '283']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '282'], 'value': '>'},{'id': '272', 'type': '()', 'children': ['273']},{'id': '273', 'type': 'boolean_operator', 'children': ['274', '278'], 'value': 'or'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '282', 'type': 'integer', 'children': [], 'value': '3'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '287', 'type': 'False', 'children': []},{'id': '288', 'type': 'if_statement', 'children': ['289', '292']},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '291'], 'value': 'is'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '291', 'type': 'None', 'children': []},{'id': '292', 'type': 'block', 'children': ['293', '310', '327', '339']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '300', 'type': 'argument_list', 'children': ['301', '302', '308']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'quad_PJ0b'},{'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '304', 'type': 'tuple', 'children': ['305', '306', '307']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'sPJ0br'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '308', 'type': 'dictionary_splat', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'integrate'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'quad'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319', '325']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'quad_PJ0b'},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '321', 'type': 'tuple', 'children': ['322', '323', '324']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'sPJ0bi'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'off'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'factAng'},{'id': '325', 'type': 'dictionary_splat', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'iinp'},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'augmented_assignment', 'children': ['329', '330'], 'value': '+='},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '330', 'type': 'binary_operator', 'children': ['331', '334'], 'value': '+'},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '333', 'type': 'integer', 'children': [], 'value': '0'},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '*'},{'id': '335', 'type': 'integer', 'children': [], 'value': '1j'},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '338', 'type': 'integer', 'children': [], 'value': '0'},{'id': '339', 'type': 'if_statement', 'children': ['340', '352']},{'id': '340', 'type': 'comparison_operator', 'children': ['341', '351'], 'value': '>'},{'id': '341', 'type': '()', 'children': ['342']},{'id': '342', 'type': 'boolean_operator', 'children': ['343', '347'], 'value': 'or'},{'id': '343', 'type': 'call', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'im'},{'id': '351', 'type': 'integer', 'children': [], 'value': '3'},{'id': '352', 'type': 'block', 'children': ['353']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'conv'},{'id': '356', 'type': 'False', 'children': []},{'id': '357', 'type': 'return_statement', 'children': ['358']},{'id': '358', 'type': 'expression_list', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'conv'} | def quad(sPJ0r, sPJ0i, sPJ1r, sPJ1i, sPJ0br, sPJ0bi, ab, off, factAng, iinp):
r
def quad_PJ0(klambd, sPJ0, koff):
r
return sPJ0(np.log(klambd))*special.j0(koff*klambd)
def quad_PJ1(klambd, sPJ1, ab, koff, kang):
r
tP1 = kang*sPJ1(np.log(klambd))
if ab in [11, 12, 21, 22, 14, 24, 15, 25]:
tP1 /= koff
return tP1*special.j1(koff*klambd)
def quad_PJ0b(klambd, sPJ0b, koff, kang):
r
return kang*sPJ0b(np.log(klambd))*special.j0(koff*klambd)
conv = True
out = np.array(0.0+0.0j)
iinp['full_output'] = 1
if sPJ0r is not None:
re = integrate.quad(quad_PJ0, args=(sPJ0r, off), **iinp)
im = integrate.quad(quad_PJ0, args=(sPJ0i, off), **iinp)
out += re[0] + 1j*im[0]
if (len(re) or len(im)) > 3:
conv = False
if sPJ1r is not None:
re = integrate.quad(quad_PJ1, args=(sPJ1r, ab, off, factAng), **iinp)
im = integrate.quad(quad_PJ1, args=(sPJ1i, ab, off, factAng), **iinp)
out += re[0] + 1j*im[0]
if (len(re) or len(im)) > 3:
conv = False
if sPJ0br is not None:
re = integrate.quad(quad_PJ0b, args=(sPJ0br, off, factAng), **iinp)
im = integrate.quad(quad_PJ0b, args=(sPJ0bi, off, factAng), **iinp)
out += re[0] + 1j*im[0]
if (len(re) or len(im)) > 3:
conv = False
return out, conv |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_participle_clause_fragment'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '5', 'type': 'block', 'children': ['6', '19', '53', '113', '138']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': '_begins_with_one_of'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '12', 'type': 'list', 'children': ['13', '14', '15'], 'value': "['VBG', 'VBN', 'JJ']"},{'id': '13', 'type': 'string', 'children': [], 'value': "'VBG'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'VBN'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'JJ'"},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '19', 'type': 'if_statement', 'children': ['20', '26']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_begins_with_one_of'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '24', 'type': 'list', 'children': ['25'], 'value': "['JJ']"},{'id': '25', 'type': 'string', 'children': [], 'value': "'JJ'"},{'id': '26', 'type': 'block', 'children': ['27', '34', '44']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nlp'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '37', 'type': 'subscript', 'children': ['38', '43']},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'if_statement', 'children': ['45', '50']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '=='},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dep_'},{'id': '49', 'type': 'string', 'children': [], 'value': "'amod'"},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_begins_with_one_of'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '58', 'type': 'list', 'children': ['59'], 'value': "['VBG']"},{'id': '59', 'type': 'string', 'children': [], 'value': "'VBG'"},{'id': '60', 'type': 'block', 'children': ['61', '68', '78', '90', '100']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'nlp'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '71', 'type': 'subscript', 'children': ['72', '77']},{'id': '72', 'type': 'list_comprehension', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'if_statement', 'children': ['79', '87']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'dep_'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "'subj'"},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '93', 'type': 'list_comprehension', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'noun_chunks'},{'id': '100', 'type': 'if_statement', 'children': ['101', '110']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '106'], 'value': 'in'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fw'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'positive_prob'},{'id': '116', 'type': 'subscript', 'children': ['117', '137']},{'id': '117', 'type': 'subscript', 'children': ['118', '136']},{'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': 'models'},{'id': '122', 'type': 'string', 'children': [], 'value': "'participle'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'list', 'children': ['126'], 'value': "[_text_to_vector(sentence,\n trigram2idx['participle'], trigram_count['participle'])]"},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_text_to_vector'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '133']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'trigram2idx'},{'id': '132', 'type': 'string', 'children': [], 'value': "'participle'"},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'trigram_count'},{'id': '135', 'type': 'string', 'children': [], 'value': "'participle'"},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'positive_prob'} | def is_participle_clause_fragment(sentence):
if not _begins_with_one_of(sentence, ['VBG', 'VBN', 'JJ']):
return 0.0
if _begins_with_one_of(sentence, ['JJ']):
doc = nlp(sentence)
fw = [w for w in doc][0]
if fw.dep_ == 'amod':
return 0.0
if _begins_with_one_of(sentence, ['VBG']):
doc = nlp(sentence)
fw = [w for w in doc][0]
if fw.dep_.endswith('subj'):
return 0.0
fc = [c for c in doc.noun_chunks]
if str(fw) in str(fc):
return 0.0
positive_prob = models['participle'].predict([_text_to_vector(sentence,
trigram2idx['participle'], trigram_count['participle'])])[0][1]
return float(positive_prob) |
{'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': 'sentence'},{'id': '5', 'type': 'block', 'children': ['6', '12', '19', '26', '33', '40', '47', '82', '119', '165', '200', '236', '310', '328']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Feedback'},{'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': 'is_missing_verb'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'detect_missing_verb'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_infinitive'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'detect_infinitive_phrase'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_participle'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'is_participle_clause_fragment'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_language_tool_feedback'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'subject_and_verb_agree'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_subject_verb_agreement_feedback'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '47', 'type': 'if_statement', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'is_missing_verb'},{'id': '49', 'type': 'block', 'children': ['50', '58', '70', '76']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '57']},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '56', 'type': 'string', 'children': [], 'value': "'missing_verb'"},{'id': '57', 'type': 'True', 'children': []},{'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': 'result'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'MISSING_VERB_ADVICE'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '69', 'type': 'string', 'children': [], 'value': "''"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '75', 'type': 'string', 'children': [], 'value': "'MISSING_VERB_ERROR'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '81', 'type': 'string', 'children': [], 'value': "'MISSING_VERB'"},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '>'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'is_participle'},{'id': '85', 'type': 'float', 'children': [], 'value': '.5'},{'id': '86', 'type': 'block', 'children': ['87', '95', '107', '113']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '94']},{'id': '89', 'type': 'subscript', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '93', 'type': 'string', 'children': [], 'value': "'participle_phrase'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'is_participle'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'PARTICIPLE_FRAGMENT_ADVICE'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '106', 'type': 'string', 'children': [], 'value': "''"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '112', 'type': 'string', 'children': [], 'value': "'FRAGMENT_ERROR'"},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '118', 'type': 'string', 'children': [], 'value': "'PARTICIPLE_PHRASE'"},{'id': '119', 'type': 'if_statement', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '121', 'type': 'block', 'children': ['122', '130']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '129']},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '128', 'type': 'string', 'children': [], 'value': "'lang_tool'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'if_statement', 'children': ['135', '142']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '141'], 'value': '=='},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '139', 'type': 'string', 'children': [], 'value': "'rule'"},{'id': '140', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '141', 'type': 'string', 'children': [], 'value': "'SENTENCE_FRAGMENT'"},{'id': '142', 'type': 'block', 'children': ['143', '153', '159']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '158', 'type': 'string', 'children': [], 'value': "'FRAGMENT_ERROR'"},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '164', 'type': 'string', 'children': [], 'value': "'SUBORDINATE_CLAUSE'"},{'id': '165', 'type': 'if_statement', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'is_infinitive'},{'id': '167', 'type': 'block', 'children': ['168', '176', '188', '194']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '175']},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '174', 'type': 'string', 'children': [], 'value': "'infinitive_phrase'"},{'id': '175', 'type': 'True', 'children': []},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'INFINITIVE_PHRASE_ADVICE'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187']},{'id': '186', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '187', 'type': 'string', 'children': [], 'value': "''"},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '193', 'type': 'string', 'children': [], 'value': "'INFINITIVE_PHRASE_ERROR'"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '199', 'type': 'string', 'children': [], 'value': "'INFINITIVE_PHRASE'"},{'id': '200', 'type': 'if_statement', 'children': ['201', '203']},{'id': '201', 'type': 'not_operator', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'subject_and_verb_agree'},{'id': '203', 'type': 'block', 'children': ['204', '212', '224', '230']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '211']},{'id': '206', 'type': 'subscript', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '210', 'type': 'string', 'children': [], 'value': "'subject_verb_agreement'"},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'subject_and_verb_agree'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'SUBJECT_VERB_AGREEMENT_ADVICE'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '223', 'type': 'string', 'children': [], 'value': "''"},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '229', 'type': 'string', 'children': [], 'value': "'SUBJECT_VERB_AGREEMENT_ERROR'"},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '235', 'type': 'string', 'children': [], 'value': "'SUBJECT_VERB_AGREEMENT'"},{'id': '236', 'type': 'if_statement', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '238', 'type': 'block', 'children': ['239', '247', '280']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '246']},{'id': '241', 'type': 'subscript', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '245', 'type': 'string', 'children': [], 'value': "'lang_tool'"},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'lang_tool_feedback'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'if_statement', 'children': ['252', '259']},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '258'], 'value': '=='},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '256', 'type': 'string', 'children': [], 'value': "'rule'"},{'id': '257', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '258', 'type': 'string', 'children': [], 'value': "'MORFOLOGIK_RULE_EN_US'"},{'id': '259', 'type': 'block', 'children': ['260', '268', '274']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '267', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '273', 'type': 'string', 'children': [], 'value': "'SPELLING_ERROR'"},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '279', 'type': 'string', 'children': [], 'value': "'SPELLING_ERROR'"},{'id': '280', 'type': 'if_statement', 'children': ['281', '285']},{'id': '281', 'type': 'not_operator', 'children': ['282']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '285', 'type': 'block', 'children': ['286', '294', '300']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '293', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'primary_error'},{'id': '299', 'type': 'string', 'children': [], 'value': "'OTHER_ERROR'"},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'specific_error'},{'id': '305', 'type': 'subscript', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'ltf'},{'id': '308', 'type': 'string', 'children': [], 'value': "'rule'"},{'id': '309', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '310', 'type': 'if_statement', 'children': ['311', '315']},{'id': '311', 'type': 'not_operator', 'children': ['312']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '315', 'type': 'block', 'children': ['316']},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'human_readable'},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'STRONG_SENTENCE_ADVICE'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '325', 'type': 'argument_list', 'children': ['326', '327']},{'id': '326', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '327', 'type': 'string', 'children': [], 'value': "''"},{'id': '328', 'type': 'return_statement', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'result'} | def check(sentence):
result = Feedback()
is_missing_verb = detect_missing_verb(sentence)
is_infinitive = detect_infinitive_phrase(sentence)
is_participle = is_participle_clause_fragment(sentence)
lang_tool_feedback = get_language_tool_feedback(sentence)
subject_and_verb_agree = get_subject_verb_agreement_feedback(sentence)
if is_missing_verb:
result.matches['missing_verb'] = True
result.human_readable = MISSING_VERB_ADVICE.replace('\n', '')
result.primary_error = 'MISSING_VERB_ERROR'
result.specific_error = 'MISSING_VERB'
if is_participle > .5:
result.matches['participle_phrase'] = is_participle
result.human_readable = PARTICIPLE_FRAGMENT_ADVICE.replace('\n', '')
result.primary_error = 'FRAGMENT_ERROR'
result.specific_error = 'PARTICIPLE_PHRASE'
if lang_tool_feedback:
result.matches['lang_tool'] = lang_tool_feedback
for ltf in lang_tool_feedback:
if ltf['rule']['id'] == 'SENTENCE_FRAGMENT':
result.human_readable = lang_tool_feedback[0]['message']
result.primary_error = 'FRAGMENT_ERROR'
result.specific_error = 'SUBORDINATE_CLAUSE'
if is_infinitive:
result.matches['infinitive_phrase'] = True
result.human_readable = INFINITIVE_PHRASE_ADVICE.replace('\n', '')
result.primary_error = 'INFINITIVE_PHRASE_ERROR'
result.specific_error = 'INFINITIVE_PHRASE'
if not subject_and_verb_agree:
result.matches['subject_verb_agreement'] = subject_and_verb_agree
result.human_readable = SUBJECT_VERB_AGREEMENT_ADVICE.replace('\n', '')
result.primary_error = 'SUBJECT_VERB_AGREEMENT_ERROR'
result.specific_error = 'SUBJECT_VERB_AGREEMENT'
if lang_tool_feedback:
result.matches['lang_tool'] = lang_tool_feedback
for ltf in lang_tool_feedback:
if ltf['rule']['id'] == 'MORFOLOGIK_RULE_EN_US':
result.human_readable = ltf['message']
result.primary_error = 'SPELLING_ERROR'
result.specific_error = 'SPELLING_ERROR'
if not result.primary_error:
result.human_readable = ltf['message']
result.primary_error = 'OTHER_ERROR'
result.specific_error = ltf['rule']['id']
if not result.matches:
result.human_readable = STRONG_SENTENCE_ADVICE.replace('\n', '')
return result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '34', '71', '79', '137', '188']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'taskset'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '23', 'type': 'dictionary', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'totaltime'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'for_statement', 'children': ['35', '36', '42']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'taskseq'},{'id': '42', 'type': 'block', 'children': ['43', '52', '65']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'taskset'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'task'},{'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': 'task'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'add_callback'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '62']},{'id': '58', 'type': 'string', 'children': [], 'value': "'resolved'"},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'child_done'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'augmented_assignment', 'children': ['67', '70'], 'value': '+='},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'numtasks'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '79', 'type': 'with_statement', 'children': ['80', '85']},{'id': '80', 'type': 'with_clause', 'children': ['81']},{'id': '81', 'type': 'with_item', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'regcond'},{'id': '85', 'type': 'block', 'children': ['86', '108', '122']},{'id': '86', 'type': 'for_statement', 'children': ['87', '88', '94']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'taskset'},{'id': '94', 'type': 'block', 'children': ['95', '102']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'initialize'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'totaltime'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '119'], 'value': '-'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'totaltime'},{'id': '122', 'type': 'while_statement', 'children': ['123', '128']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '>'},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'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': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'regcond'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '146']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'block', 'children': ['147', '155']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '150', 'type': 'subscript', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '155', 'type': 'if_statement', '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': 'Exception'},{'id': '161', 'type': 'block', 'children': ['162', '168', '186']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '167']},{'id': '164', 'type': 'tuple_pattern', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'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': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'},{'id': '177', 'type': 'string', 'children': [], 'value': '"Child task %s terminated with exception: %s"'},{'id': '178', 'type': 'tuple', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '186', 'type': 'raise_statement', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'} | def execute(self):
self.count = 0
self.taskset = []
self.results = {}
self.totaltime = time.time()
for task in list(self.taskseq):
self.taskset.append(task)
task.add_callback('resolved', self.child_done, self.count)
self.count += 1
self.numtasks = self.count
with self.regcond:
for task in list(self.taskset):
task.initialize(self)
task.start()
self.totaltime = time.time() - self.totaltime
while self.count > 0:
self.regcond.wait()
for key in self.results.keys():
value = self.results[key]
if isinstance(value, Exception):
(count, task) = key
self.logger.error("Child task %s terminated with exception: %s" % (
task.tag, str(value)))
raise value
return 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'startall'},{'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': 'wait'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwdargs'},{'id': '10', 'type': 'block', 'children': ['11', '20']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"startall called"'},{'id': '20', 'type': 'with_statement', 'children': ['21', '26']},{'id': '21', 'type': 'with_clause', 'children': ['22']},{'id': '22', 'type': 'with_item', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'regcond'},{'id': '26', 'type': 'block', 'children': ['27', '82', '92', '98', '104', '110', '123', '132', '182', '230']},{'id': '27', 'type': 'while_statement', 'children': ['28', '33']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '!='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '32', 'type': 'string', 'children': [], 'value': "'down'"},{'id': '33', 'type': 'block', 'children': ['34', '61', '74']},{'id': '34', 'type': 'if_statement', 'children': ['35', '50']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '43'], 'value': 'or'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': 'in'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '40', 'type': 'tuple', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'up'"},{'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': 'ev_quit'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'block', 'children': ['51', '60']},{'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': 'error'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"ignoring duplicate request to start thread pool"'},{'id': '60', 'type': 'return_statement', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'},{'id': '70', 'type': 'string', 'children': [], 'value': '"waiting for threads: count=%d"'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'runningcount'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'regcond'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'if_statement', 'children': ['83', '90']},{'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': 'ev_quit'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'return_statement', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'runningcount'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '103', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '109', 'type': 'list', 'children': [], 'value': '[]'},{'id': '110', 'type': 'if_statement', 'children': ['111', '112', '117']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'tpool'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tpool'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': '"starting threads in thread pool"'},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '140']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'numthreads'},{'id': '140', 'type': 'block', 'children': ['141', '167', '176']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'workerClass'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152', '157', '162', '165']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ev_quit'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ev_quit'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'tpool'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'tpool'},{'id': '165', 'type': 'dictionary_splat', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'kwdargs'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '174']},{'id': '169', 'type': 'attribute', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '184', '222']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'while_statement', 'children': ['186', '200']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '192'], 'value': 'and'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '!='},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '191', 'type': 'string', 'children': [], 'value': "'up'"},{'id': '192', 'type': 'not_operator', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ev_quit'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'block', 'children': ['201', '214']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'},{'id': '210', 'type': 'string', 'children': [], 'value': '"waiting for threads: count=%d"'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'runningcount'},{'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': 'regcond'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '221', 'type': 'argument_list', 'children': []},{'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': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '229', 'type': 'string', 'children': [], 'value': "'up'"},{'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': 'debug'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'string', 'children': [], 'value': '"startall done"'} | def startall(self, wait=False, **kwdargs):
self.logger.debug("startall called")
with self.regcond:
while self.status != 'down':
if self.status in ('start', 'up') or self.ev_quit.is_set():
self.logger.error("ignoring duplicate request to start thread pool")
return
self.logger.debug("waiting for threads: count=%d" %
self.runningcount)
self.regcond.wait()
if self.ev_quit.is_set():
return
self.runningcount = 0
self.status = 'start'
self.workers = []
if wait:
tpool = self
else:
tpool = None
self.logger.debug("starting threads in thread pool")
for i in range(self.numthreads):
t = self.workerClass(self.queue, logger=self.logger,
ev_quit=self.ev_quit, tpool=tpool,
**kwdargs)
self.workers.append(t)
t.start()
if wait:
while self.status != 'up' and not self.ev_quit.is_set():
self.logger.debug("waiting for threads: count=%d" %
self.runningcount)
self.regcond.wait()
else:
self.status = 'up'
self.logger.debug("startall done") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '22', '30', '38', '47', '58', '65', '71', '491']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'iis'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dataout'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'wfile'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'calcsize'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'8h'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'line'},{'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': 'packet'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '<'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': []},{'id': '71', 'type': 'while_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '>'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'block', 'children': ['76', '113', '119', '125', '131', '139', '147', '155', '163', '170', '182', '188', '194', '200', '206', '212', '218', '224', '230', '243', '411', '467', '478', '485']},{'id': '76', 'type': 'try_statement', 'children': ['77', '88']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'8h'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'except_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '90', 'type': 'block', 'children': ['91', '100']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '98']},{'id': '93', 'type': 'attribute', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'error unpacking the data.'"},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '107']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'exctn'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'exctn'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'subunit'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '&'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'subunit'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0o77'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '138'], 'value': '&'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '137', 'type': 'integer', 'children': [], 'value': '4'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0o177777'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '&'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '145', 'type': 'integer', 'children': [], 'value': '5'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0o177777'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '154'], 'value': '&'},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '153', 'type': 'integer', 'children': [], 'value': '6'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0o177777'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '&'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '161', 'type': 'integer', 'children': [], 'value': '7'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0o17777'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ndatabytes'},{'id': '166', 'type': 'unary_operator', 'children': ['167'], 'value': '-'},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'if_statement', 'children': ['171', '177']},{'id': '171', 'type': '()', 'children': ['172']},{'id': '172', 'type': 'not_operator', 'children': ['173']},{'id': '173', 'type': '()', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '&'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'PACKED'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'augmented_assignment', 'children': ['180', '181'], 'value': '*='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ndatabytes'},{'id': '181', 'type': 'integer', 'children': [], 'value': '2'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'subunit'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'subunit'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'packet'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'z'},{'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': 'packet'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ndatabytes'},{'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': 'debug'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '%'},{'id': '239', 'type': 'string', 'children': [], 'value': '"PACKET IS %o"'},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'subunit'},{'id': '243', 'type': 'if_statement', 'children': ['244', '249', '257', '290', '329', '362', '395']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '=='},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'FEEDBACK'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'handle_feedback'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '257', 'type': 'elif_clause', 'children': ['258', '263']},{'id': '258', 'type': 'comparison_operator', 'children': ['259', '262'], 'value': '=='},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'LUT'},{'id': '263', 'type': 'block', 'children': ['264', '271', '282', '289']},{'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': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'handle_lut'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '289', 'type': 'continue_statement', 'children': []},{'id': '290', 'type': 'elif_clause', 'children': ['291', '296']},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '295'], 'value': '=='},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'MEMORY'},{'id': '296', 'type': 'block', 'children': ['297', '304', '310', '321', '328']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'handle_memory'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '304', 'type': 'if_statement', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'pass_statement', 'children': []},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '313', 'type': 'call', 'children': ['314', '319']},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '328', 'type': 'continue_statement', 'children': []},{'id': '329', 'type': 'elif_clause', 'children': ['330', '335']},{'id': '330', 'type': 'comparison_operator', 'children': ['331', '334'], 'value': '=='},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'WCS'},{'id': '335', 'type': 'block', 'children': ['336', '343', '354', '361']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'handle_wcs'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '346', 'type': 'call', 'children': ['347', '352']},{'id': '347', 'type': 'attribute', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '361', 'type': 'continue_statement', 'children': []},{'id': '362', 'type': 'elif_clause', 'children': ['363', '368']},{'id': '363', 'type': 'comparison_operator', 'children': ['364', '367'], 'value': '=='},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'IMCURSOR'},{'id': '368', 'type': 'block', 'children': ['369', '376', '387', '394']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'handle_imcursor'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'assignment', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '379', 'type': 'call', 'children': ['380', '385']},{'id': '380', 'type': 'attribute', 'children': ['381', '384']},{'id': '381', 'type': 'attribute', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'assignment', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '390', 'type': 'call', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '392', 'type': 'argument_list', 'children': ['393']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '394', 'type': 'continue_statement', 'children': []},{'id': '395', 'type': 'else_clause', 'children': ['396']},{'id': '396', 'type': 'block', 'children': ['397']},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'call', 'children': ['399', '404']},{'id': '399', 'type': 'attribute', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'binary_operator', 'children': ['406', '407'], 'value': '%'},{'id': '406', 'type': 'string', 'children': [], 'value': "'?NO OP (0%o)'"},{'id': '407', 'type': '()', 'children': ['408']},{'id': '408', 'type': 'attribute', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'subunit077'},{'id': '411', 'type': 'if_statement', 'children': ['412', '419']},{'id': '412', 'type': 'not_operator', 'children': ['413']},{'id': '413', 'type': '()', 'children': ['414']},{'id': '414', 'type': 'binary_operator', 'children': ['415', '418'], 'value': '&'},{'id': '415', 'type': 'attribute', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'tid'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'IIS_READ'},{'id': '419', 'type': 'block', 'children': ['420', '426']},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'assignment', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '426', 'type': 'while_statement', 'children': ['427', '430']},{'id': '427', 'type': 'comparison_operator', 'children': ['428', '429'], 'value': '>'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '429', 'type': 'integer', 'children': [], 'value': '0'},{'id': '430', 'type': 'block', 'children': ['431', '446', '457', '463']},{'id': '431', 'type': 'if_statement', 'children': ['432', '435', '440']},{'id': '432', 'type': 'comparison_operator', 'children': ['433', '434'], 'value': '<'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'SZ_FIFOBUF'},{'id': '435', 'type': 'block', 'children': ['436']},{'id': '436', 'type': 'expression_statement', 'children': ['437']},{'id': '437', 'type': 'assignment', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '440', 'type': 'else_clause', 'children': ['441']},{'id': '441', 'type': 'block', 'children': ['442']},{'id': '442', 'type': 'expression_statement', 'children': ['443']},{'id': '443', 'type': 'assignment', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'SZ_FIFOBUF'},{'id': '446', 'type': 'expression_statement', 'children': ['447']},{'id': '447', 'type': 'assignment', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '449', 'type': 'call', 'children': ['450', '455']},{'id': '450', 'type': 'attribute', 'children': ['451', '454']},{'id': '451', 'type': 'attribute', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'rfile'},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '455', 'type': 'argument_list', 'children': ['456']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '457', 'type': 'if_statement', 'children': ['458', '461']},{'id': '458', 'type': 'comparison_operator', 'children': ['459', '460'], 'value': '<='},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '460', 'type': 'integer', 'children': [], 'value': '0'},{'id': '461', 'type': 'block', 'children': ['462']},{'id': '462', 'type': 'break_statement', 'children': []},{'id': '463', 'type': 'expression_statement', 'children': ['464']},{'id': '464', 'type': 'augmented_assignment', 'children': ['465', '466'], 'value': '-='},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'nbytes'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '467', 'type': 'expression_statement', 'children': ['468']},{'id': '468', 'type': 'assignment', 'children': ['469', '470']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '470', 'type': 'call', 'children': ['471', '476']},{'id': '471', 'type': 'attribute', 'children': ['472', '475']},{'id': '472', 'type': 'attribute', 'children': ['473', '474']},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'packet'},{'id': '474', 'type': 'identifier', 'children': [], 'value': 'datain'},{'id': '475', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '476', 'type': 'argument_list', 'children': ['477']},{'id': '477', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '478', 'type': 'expression_statement', 'children': ['479']},{'id': '479', 'type': 'assignment', 'children': ['480', '481']},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '481', 'type': 'call', 'children': ['482', '483']},{'id': '482', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '483', 'type': 'argument_list', 'children': ['484']},{'id': '484', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '485', 'type': 'if_statement', 'children': ['486', '489']},{'id': '486', 'type': 'comparison_operator', 'children': ['487', '488'], 'value': '<'},{'id': '487', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '488', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '489', 'type': 'block', 'children': ['490']},{'id': '490', 'type': 'return_statement', 'children': []},{'id': '491', 'type': 'if_statement', 'children': ['492', '495']},{'id': '492', 'type': 'attribute', 'children': ['493', '494']},{'id': '493', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '494', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '495', 'type': 'block', 'children': ['496', '502']},{'id': '496', 'type': 'expression_statement', 'children': ['497']},{'id': '497', 'type': 'call', 'children': ['498', '501']},{'id': '498', 'type': 'attribute', 'children': ['499', '500']},{'id': '499', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '500', 'type': 'identifier', 'children': [], 'value': 'display_image'},{'id': '501', 'type': 'argument_list', 'children': []},{'id': '502', 'type': 'expression_statement', 'children': ['503']},{'id': '503', 'type': 'assignment', 'children': ['504', '507']},{'id': '504', 'type': 'attribute', 'children': ['505', '506']},{'id': '505', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '506', 'type': 'identifier', 'children': [], 'value': 'needs_update'},{'id': '507', 'type': 'False', 'children': []} | def handle(self):
self.logger = self.server.logger
packet = iis()
packet.datain = self.rfile
packet.dataout = self.wfile
size = struct.calcsize('8h')
line = packet.datain.read(size)
n = len(line)
if n < size:
return
while n > 0:
try:
bytes = struct.unpack('8h', line)
except Exception:
self.logger.error('error unpacking the data.')
for exctn in sys.exc_info():
print(exctn)
subunit = bytes[2]
subunit077 = subunit & 0o77
tid = bytes[0]
x = bytes[4] & 0o177777
y = bytes[5] & 0o177777
z = bytes[6] & 0o177777
t = bytes[7] & 0o17777
ndatabytes = - bytes[1]
if (not(tid & PACKED)):
ndatabytes *= 2
packet.subunit = subunit
packet.subunit077 = subunit077
packet.tid = tid
packet.x = x
packet.y = y
packet.z = z
packet.t = t
packet.nbytes = ndatabytes
self.logger.debug("PACKET IS %o" % packet.subunit)
if packet.subunit077 == FEEDBACK:
self.handle_feedback(packet)
elif packet.subunit077 == LUT:
self.handle_lut(packet)
line = packet.datain.read(size)
n = len(line)
continue
elif packet.subunit077 == MEMORY:
self.handle_memory(packet)
if self.needs_update:
pass
line = packet.datain.read(size)
n = len(line)
continue
elif packet.subunit077 == WCS:
self.handle_wcs(packet)
line = packet.datain.read(size)
n = len(line)
continue
elif packet.subunit077 == IMCURSOR:
self.handle_imcursor(packet)
line = packet.datain.read(size)
n = len(line)
continue
else:
self.logger.debug('?NO OP (0%o)' % (packet.subunit077))
if not (packet.tid & IIS_READ):
nbytes = packet.nbytes
while nbytes > 0:
if nbytes < SZ_FIFOBUF:
n = nbytes
else:
n = SZ_FIFOBUF
m = self.rfile.read(n)
if m <= 0:
break
nbytes -= n
line = packet.datain.read(size)
n = len(line)
if n < size:
return
if self.needs_update:
self.display_image()
self.needs_update = False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_file'},{'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': 'filepath'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'create_channel'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'display_image'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '66', '72', '83', '97', '109', '133', '139', '143', '147', '162', '201', '209', '219', '231', '251', '261', '287', '337']},{'id': '22', 'type': 'if_statement', 'children': ['23', '25', '34']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'chname'},{'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': 'channel'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_current_channel'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36', '57']},{'id': '36', 'type': 'if_statement', 'children': ['37', '46']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '45'], 'value': 'and'},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'has_channel'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'create_channel'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'gui_call'},{'id': '52', 'type': 'argument_list', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'add_channel'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_channel'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'load_image'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'cache_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': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'download_folder'"},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tmpdir'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'iohelper'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_fileinfo'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'cache_dir'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cache_dir'},{'id': '109', 'type': 'if_statement', 'children': ['110', '114']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ondisk'},{'id': '114', 'type': 'block', 'children': ['115', '122', '132']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '%'},{'id': '119', 'type': 'string', 'children': [], 'value': '"File must be locally loadable: %s"'},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'gui_do'},{'id': '127', 'type': 'argument_list', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'show_error'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '132', 'type': 'return_statement', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '142', 'type': 'dictionary', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '153']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': 'is'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'numhdu'},{'id': '152', 'type': 'None', 'children': []},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '158', 'type': 'string', 'children': [], 'value': "'idx'"},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'numhdu'},{'id': '162', 'type': 'try_statement', 'children': ['163', '173']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '171', 'type': 'dictionary_splat', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '173', 'type': 'except_clause', 'children': ['174', '178']},{'id': '174', 'type': 'as_pattern', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '176', 'type': 'as_pattern_target', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '178', 'type': 'block', 'children': ['179', '190', '200']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '%'},{'id': '183', 'type': 'string', 'children': [], 'value': '"Failed to load \'%s\': %s"'},{'id': '184', 'type': 'tuple', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'gui_do'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'show_error'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'errmsg'},{'id': '200', 'type': 'return_statement', 'children': []},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Future'},{'id': '208', 'type': 'argument_list', 'children': []},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'freeze'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '217', 'type': 'dictionary_splat', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '224', 'type': 'argument_list', 'children': ['225', '228']},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'loader'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'image_loader'},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'image_future'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '231', 'type': 'if_statement', 'children': ['232', '241']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '240'], 'value': 'is'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '239', 'type': 'None', 'children': []},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '260', 'type': 'None', 'children': []},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'is'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '264', 'type': 'None', 'children': []},{'id': '265', 'type': 'block', 'children': ['266', '278']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'iohelper'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'name_image_from_path'},{'id': '273', 'type': 'argument_list', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '287', 'type': 'if_statement', 'children': ['288', '289', '323']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'display_image'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'if_statement', 'children': ['291', '292', '307']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'wait'},{'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': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'gui_call'},{'id': '298', 'type': 'argument_list', 'children': ['299', '302', '303', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'add_image'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '307', 'type': 'else_clause', 'children': ['308']},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'gui_do'},{'id': '314', 'type': 'argument_list', 'children': ['315', '318', '319', '320']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'add_image'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '323', 'type': 'else_clause', 'children': ['324']},{'id': '324', 'type': 'block', 'children': ['325']},{'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': 'self'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'gui_do'},{'id': '330', 'type': 'argument_list', 'children': ['331', '334', '335', '336']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'bulk_add_image'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '337', 'type': 'return_statement', 'children': ['338']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'image'} | def load_file(self, filepath, chname=None, wait=True,
create_channel=True, display_image=True,
image_loader=None):
if not chname:
channel = self.get_current_channel()
else:
if not self.has_channel(chname) and create_channel:
self.gui_call(self.add_channel, chname)
channel = self.get_channel(chname)
chname = channel.name
if image_loader is None:
image_loader = self.load_image
cache_dir = self.settings.get('download_folder', self.tmpdir)
info = iohelper.get_fileinfo(filepath, cache_dir=cache_dir)
if not info.ondisk:
errmsg = "File must be locally loadable: %s" % (filepath)
self.gui_do(self.show_error, errmsg)
return
filepath = info.filepath
kwargs = {}
idx = None
if info.numhdu is not None:
kwargs['idx'] = info.numhdu
try:
image = image_loader(filepath, **kwargs)
except Exception as e:
errmsg = "Failed to load '%s': %s" % (filepath, str(e))
self.gui_do(self.show_error, errmsg)
return
future = Future.Future()
future.freeze(image_loader, filepath, **kwargs)
image.set(loader=image_loader, image_future=future)
if image.get('path', None) is None:
image.set(path=filepath)
name = image.get('name', None)
if name is None:
name = iohelper.name_image_from_path(filepath, idx=idx)
image.set(name=name)
if display_image:
if wait:
self.gui_call(self.add_image, name, image, chname=chname)
else:
self.gui_do(self.add_image, name, image, chname=chname)
else:
self.gui_do(self.bulk_add_image, name, image, chname)
return image |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'open_uris'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'uris'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bulk_add'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '22', '47', '56', '74', '90', '108', '124', '149', '155']},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '=='},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'uris'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': []},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '35', '41']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_channel_info'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'channel'},{'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': 'get_channel_on_demand'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '56', 'type': 'function_definition', 'children': ['57', '58', '60']},{'id': '57', 'type': 'function_name', 'children': [], 'value': 'show_dataobj_bulk'},{'id': '58', 'type': 'parameters', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'data_obj'},{'id': '60', 'type': 'block', 'children': ['61']},{'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': 'gui_do'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70', '71']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'add_image'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'data_obj'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bulk_add'},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'function_definition', 'children': ['75', '76', '78']},{'id': '75', 'type': 'function_name', 'children': [], 'value': 'load_file_bulk'},{'id': '76', 'type': 'parameters', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'nongui_do'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88', '89']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'open_file_cont'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'show_dataobj_bulk'},{'id': '90', 'type': 'function_definition', 'children': ['91', '92', '94']},{'id': '91', 'type': 'function_name', 'children': [], 'value': 'show_dataobj'},{'id': '92', 'type': 'parameters', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data_obj'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'gui_do'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104', '105']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'add_image'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'data_obj'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'bulk_add'},{'id': '107', 'type': 'False', 'children': []},{'id': '108', 'type': 'function_definition', 'children': ['109', '110', '112']},{'id': '109', 'type': 'function_name', 'children': [], 'value': 'load_file'},{'id': '110', 'type': 'parameters', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nongui_do'},{'id': '118', 'type': 'argument_list', 'children': ['119', '122', '123']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'open_file_cont'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'show_dataobj'},{'id': '124', 'type': 'if_statement', 'children': ['125', '126', '137']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'bulk_add'},{'id': '126', 'type': 'block', 'children': ['127']},{'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': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'open_uri_cont'},{'id': '132', 'type': 'argument_list', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'uris'},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'load_file_bulk'},{'id': '137', 'type': 'else_clause', 'children': ['138']},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'open_uri_cont'},{'id': '144', 'type': 'argument_list', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'uris'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'load_file'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'update_pending'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'for_statement', 'children': ['156', '157', '162']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'uris'},{'id': '159', 'type': 'slice', 'children': ['160', '161']},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'colon', 'children': []},{'id': '162', 'type': 'block', 'children': ['163', '171']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'open_uri_cont'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'load_file_bulk'},{'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': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'update_pending'},{'id': '176', 'type': 'argument_list', 'children': []} | def open_uris(self, uris, chname=None, bulk_add=False):
if len(uris) == 0:
return
if chname is None:
channel = self.get_channel_info()
if channel is None:
return
chname = channel.name
channel = self.get_channel_on_demand(chname)
def show_dataobj_bulk(data_obj):
self.gui_do(channel.add_image, data_obj, bulk_add=True)
def load_file_bulk(filepath):
self.nongui_do(self.open_file_cont, filepath, show_dataobj_bulk)
def show_dataobj(data_obj):
self.gui_do(channel.add_image, data_obj, bulk_add=False)
def load_file(filepath):
self.nongui_do(self.open_file_cont, filepath, show_dataobj)
if bulk_add:
self.open_uri_cont(uris[0], load_file_bulk)
else:
self.open_uri_cont(uris[0], load_file)
self.update_pending()
for uri in uris[1:]:
self.open_uri_cont(uri, load_file_bulk)
self.update_pending() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_channel'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'num_images'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'settings_template'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'settings_share'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'share_keylist'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'with_statement', 'children': ['26', '31']},{'id': '26', 'type': 'with_clause', 'children': ['27']},{'id': '27', 'type': 'with_item', 'children': ['28']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '31', 'type': 'block', 'children': ['32', '47', '67', '71', '180', '201', '224', '251', '263', '277', '290', '302', '320', '328', '336', '344', '353', '361', '369', '375', '383', '391', '400', '408', '424', '469', '477']},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'has_channel'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_channel'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '47', 'type': 'if_statement', 'children': ['48', '58']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'chname'},{'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': 'ds'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_tabnames'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'raise_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'string', 'children': [], 'value': '"Tab name already in use: \'%s\'"'},{'id': '65', 'type': '()', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'block', 'children': ['76', '89']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'prefs'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'create_category'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '+'},{'id': '87', 'type': 'string', 'children': [], 'value': "'channel_'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '89', 'type': 'try_statement', 'children': ['90', '100']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'onError'},{'id': '99', 'type': 'string', 'children': [], 'value': "'raise'"},{'id': '100', 'type': 'except_clause', 'children': ['101', '105']},{'id': '101', 'type': 'as_pattern', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '105', 'type': 'block', 'children': ['106', '124']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '%'},{'id': '115', 'type': 'concatenated_string', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': '"no saved preferences found for channel "'},{'id': '117', 'type': 'string', 'children': [], 'value': '"\'%s\': %s"'},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'e'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128', '140']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'settings_template'},{'id': '127', 'type': 'None', 'children': []},{'id': '128', 'type': 'block', 'children': ['129', '133']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'osettings'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'settings_template'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'osettings'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'copy_settings'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'try_statement', 'children': ['143', '176']},{'id': '143', 'type': 'block', 'children': ['144', '155', '169']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'osettings'},{'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': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'prefs'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'get_settings'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': "'channel_Image'"},{'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': 'logger'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '167'], 'value': '%'},{'id': '164', 'type': 'concatenated_string', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': '"Copying settings from \'Image\' to "'},{'id': '166', 'type': 'string', 'children': [], 'value': '"\'%s\'"'},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'osettings'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'copy_settings'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '176', 'type': 'except_clause', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'pass_statement', 'children': []},{'id': '180', 'type': 'if_statement', 'children': ['181', '190']},{'id': '181', 'type': 'boolean_operator', 'children': ['182', '186'], 'value': 'and'},{'id': '182', 'type': '()', 'children': ['183']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'is'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'share_keylist'},{'id': '185', 'type': 'None', 'children': []},{'id': '186', 'type': '()', 'children': ['187']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'settings_share'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'settings_share'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'share_settings'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'keylist'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'share_keylist'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'num_images'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'num_images'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'numImages'"},{'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': 'settings'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'numImages'"},{'id': '223', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'settings'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'set_defaults'},{'id': '229', 'type': 'argument_list', 'children': ['230', '233', '236', '239', '242', '245', '248']},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'switchnew'},{'id': '232', 'type': 'True', 'children': []},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'numImages'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'num_images'},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'raisenew'},{'id': '238', 'type': 'True', 'children': []},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'genthumb'},{'id': '241', 'type': 'True', 'children': []},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'focus_indicator'},{'id': '244', 'type': 'False', 'children': []},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'preload_images'},{'id': '247', 'type': 'False', 'children': []},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '250', 'type': 'string', 'children': [], 'value': "'loadtime'"},{'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': 'debug'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'binary_operator', 'children': ['260', '261'], 'value': '%'},{'id': '260', 'type': 'string', 'children': [], 'value': '"Adding channel \'%s\'"'},{'id': '261', 'type': '()', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'Channel'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271', '274']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'datasrc'},{'id': '273', 'type': 'None', 'children': []},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'add_viewer'},{'id': '284', 'type': 'argument_list', 'children': ['285', '286', '287']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'image_viewer'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'set_name'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '%'},{'id': '299', 'type': 'string', 'children': [], 'value': "'channel:%s'"},{'id': '300', 'type': '()', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'opmon'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'get_plugin_manager'},{'id': '309', 'type': 'argument_list', 'children': ['310', '313', '314', '317']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'ds'},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'widget'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'container'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'connect_viewer'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'image_viewer'},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'assignment', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'viewer'},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'image_viewer'},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'fitsimage'},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'image_viewer'},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '374']},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'opmon'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'opmon'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'assignment', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '382', 'type': 'argument_list', 'children': []},{'id': '383', 'type': 'expression_statement', 'children': ['384']},{'id': '384', 'type': 'assignment', 'children': ['385', '390']},{'id': '385', 'type': 'subscript', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'call', 'children': ['393', '398']},{'id': '393', 'type': 'attribute', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'channel_names'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '407']},{'id': '402', 'type': 'attribute', 'children': ['403', '406']},{'id': '403', 'type': 'attribute', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'channel_names'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '407', 'type': 'argument_list', 'children': []},{'id': '408', 'type': 'if_statement', 'children': ['409', '417']},{'id': '409', 'type': 'comparison_operator', 'children': ['410', '416'], 'value': '=='},{'id': '410', 'type': 'call', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '412', 'type': 'argument_list', 'children': ['413']},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'channel_names'},{'id': '416', 'type': 'integer', 'children': [], 'value': '1'},{'id': '417', 'type': 'block', 'children': ['418']},{'id': '418', 'type': 'expression_statement', 'children': ['419']},{'id': '419', 'type': 'assignment', 'children': ['420', '423']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'cur_channel'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '424', 'type': 'for_statement', 'children': ['425', '426', '431']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'get_plugins'},{'id': '430', 'type': 'argument_list', 'children': []},{'id': '431', 'type': 'block', 'children': ['432', '447']},{'id': '432', 'type': 'expression_statement', 'children': ['433']},{'id': '433', 'type': 'assignment', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '435', 'type': 'call', 'children': ['436', '439']},{'id': '436', 'type': 'attribute', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '439', 'type': 'argument_list', 'children': ['440', '441']},{'id': '440', 'type': 'string', 'children': [], 'value': "'klass'"},{'id': '441', 'type': 'call', 'children': ['442', '445']},{'id': '442', 'type': 'attribute', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '445', 'type': 'argument_list', 'children': ['446']},{'id': '446', 'type': 'string', 'children': [], 'value': "'module'"},{'id': '447', 'type': 'if_statement', 'children': ['448', '457']},{'id': '448', 'type': 'comparison_operator', 'children': ['449', '456'], 'value': '=='},{'id': '449', 'type': 'call', 'children': ['450', '453']},{'id': '450', 'type': 'attribute', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '453', 'type': 'argument_list', 'children': ['454', '455']},{'id': '454', 'type': 'string', 'children': [], 'value': "'ptype'"},{'id': '455', 'type': 'string', 'children': [], 'value': "'global'"},{'id': '456', 'type': 'string', 'children': [], 'value': "'local'"},{'id': '457', 'type': 'block', 'children': ['458']},{'id': '458', 'type': 'expression_statement', 'children': ['459']},{'id': '459', 'type': 'call', 'children': ['460', '463']},{'id': '460', 'type': 'attribute', 'children': ['461', '462']},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'opmon'},{'id': '462', 'type': 'identifier', 'children': [], 'value': 'load_plugin'},{'id': '463', 'type': 'argument_list', 'children': ['464', '465', '466']},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'opname'},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '466', 'type': 'keyword_argument', 'children': ['467', '468']},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'chinfo'},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '469', 'type': 'expression_statement', 'children': ['470']},{'id': '470', 'type': 'call', 'children': ['471', '474']},{'id': '471', 'type': 'attribute', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'make_gui_callback'},{'id': '474', 'type': 'argument_list', 'children': ['475', '476']},{'id': '475', 'type': 'string', 'children': [], 'value': "'add-channel'"},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '477', 'type': 'return_statement', 'children': ['478']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'channel'} | def add_channel(self, chname, workspace=None,
num_images=None, settings=None,
settings_template=None,
settings_share=None, share_keylist=None):
with self.lock:
if self.has_channel(chname):
return self.get_channel(chname)
if chname in self.ds.get_tabnames(None):
raise ValueError("Tab name already in use: '%s'" % (chname))
name = chname
if settings is None:
settings = self.prefs.create_category('channel_' + name)
try:
settings.load(onError='raise')
except Exception as e:
self.logger.warning("no saved preferences found for channel "
"'%s': %s" % (name, str(e)))
if settings_template is not None:
osettings = settings_template
osettings.copy_settings(settings)
else:
try:
osettings = self.prefs.get_settings('channel_Image')
self.logger.debug("Copying settings from 'Image' to "
"'%s'" % (name))
osettings.copy_settings(settings)
except KeyError:
pass
if (share_keylist is not None) and (settings_share is not None):
settings_share.share_settings(settings, keylist=share_keylist)
if num_images is None:
num_images = settings.get('numImages',
self.settings.get('numImages', 1))
settings.set_defaults(switchnew=True, numImages=num_images,
raisenew=True, genthumb=True,
focus_indicator=False,
preload_images=False, sort_order='loadtime')
self.logger.debug("Adding channel '%s'" % (chname))
channel = Channel(chname, self, datasrc=None,
settings=settings)
bnch = self.add_viewer(chname, settings,
workspace=workspace)
bnch.image_viewer.set_name('channel:%s' % (chname))
opmon = self.get_plugin_manager(self.logger, self,
self.ds, self.mm)
channel.widget = bnch.widget
channel.container = bnch.container
channel.workspace = bnch.workspace
channel.connect_viewer(bnch.image_viewer)
channel.viewer = bnch.image_viewer
channel.fitsimage = bnch.image_viewer
channel.opmon = opmon
name = chname.lower()
self.channel[name] = channel
self.channel_names.append(chname)
self.channel_names.sort()
if len(self.channel_names) == 1:
self.cur_channel = channel
for spec in self.get_plugins():
opname = spec.get('klass', spec.get('module'))
if spec.get('ptype', 'global') == 'local':
opmon.load_plugin(opname, spec, chinfo=channel)
self.make_gui_callback('add-channel', channel)
return channel |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mode_key_down'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'viewer'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'keyname'},{'id': '7', 'type': 'block', 'children': ['8', '50', '56', '71', '87', '100', '189']},{'id': '8', 'type': 'if_statement', 'children': ['9', '14', '40']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'not'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'keyname'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'mode_map'},{'id': '14', 'type': 'block', 'children': ['15', '32']},{'id': '15', 'type': 'if_statement', 'children': ['16', '29']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '23'], 'value': 'or'},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'not'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'keyname'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'mode_tbl'},{'id': '23', 'type': '()', 'children': ['24']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '!='},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '28', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'mode_tbl'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keyname'},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mode_map'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'keyname'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mode_name'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '%'},{'id': '65', 'type': 'string', 'children': [], 'value': '"cur mode=\'%s\' mode pressed=\'%s\'"'},{'id': '66', 'type': 'tuple', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'mode_name'},{'id': '71', 'type': 'if_statement', 'children': ['72', '77']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '=='},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'mode_name'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '77', 'type': 'block', 'children': ['78', '85']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reset_mode'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'viewer'},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'True', 'children': []},{'id': '87', 'type': 'if_statement', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '_delayed_reset'},{'id': '91', 'type': 'block', 'children': ['92', '98']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_delayed_reset'},{'id': '97', 'type': 'False', 'children': []},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'True', 'children': []},{'id': '100', 'type': 'if_statement', 'children': ['101', '122']},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '118'], 'value': 'or'},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '112'], 'value': 'or'},{'id': '104', 'type': '()', 'children': ['105']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '109'], 'value': 'in'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '112', 'type': '()', 'children': ['113']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': '!='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_kbdmode_type'},{'id': '117', 'type': 'string', 'children': [], 'value': "'locked'"},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'mode_name'},{'id': '121', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '122', 'type': 'block', 'children': ['123', '137']},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': 'is'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'reset_mode'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'viewer'},{'id': '137', 'type': 'if_statement', 'children': ['138', '145']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': 'in'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_kbdmode'},{'id': '142', 'type': 'tuple', 'children': ['143', '144']},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '145', 'type': 'block', 'children': ['146', '152', '163', '171', '187']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'mode_type'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': 'is'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mode_type'},{'id': '155', 'type': 'None', 'children': []},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'mode_type'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_kbdmode_type_default'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'set_mode'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mode_name'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'mode_type'},{'id': '171', 'type': 'if_statement', 'children': ['172', '177']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '176'], 'value': 'is'},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'viewer'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'onscreen_message'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'bnch'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '187', 'type': 'return_statement', 'children': ['188']},{'id': '188', 'type': 'True', 'children': []},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'False', 'children': []} | def mode_key_down(self, viewer, keyname):
if keyname not in self.mode_map:
if (keyname not in self.mode_tbl) or (self._kbdmode != 'meta'):
return False
bnch = self.mode_tbl[keyname]
else:
bnch = self.mode_map[keyname]
mode_name = bnch.name
self.logger.debug("cur mode='%s' mode pressed='%s'" % (
self._kbdmode, mode_name))
if mode_name == self._kbdmode:
self.reset_mode(viewer)
return True
if self._delayed_reset:
self._delayed_reset = False
return True
if ((self._kbdmode in (None, 'meta')) or
(self._kbdmode_type != 'locked') or (mode_name == 'meta')):
if self._kbdmode is not None:
self.reset_mode(viewer)
if self._kbdmode in (None, 'meta'):
mode_type = bnch.type
if mode_type is None:
mode_type = self._kbdmode_type_default
self.set_mode(mode_name, mode_type)
if bnch.msg is not None:
viewer.onscreen_message(bnch.msg)
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_sort_cb'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '7', 'type': 'block', 'children': ['8', '16']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_options'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'index'},{'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': 't_'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'} | def set_sort_cb(self, w, index):
name = self.sort_options[index]
self.t_.set(sort_order=name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'redo'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '23', '33', '48', '58', '197', '212', '222', '232', '244', '250', '254', '307']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'image'},{'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': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_current_image'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '47']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'fv'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'show_error'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"Cannot open image: no value for metadata key \'path\'"'},{'id': '47', 'type': 'return_statement', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '55']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'asdf'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'if_statement', 'children': ['59', '64']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '!='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'img_path'},{'id': '64', 'type': 'block', 'children': ['65', '71', '92', '107', '116', '127', '143', '149', '163', '179']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'img_path'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'if_statement', 'children': ['72', '77']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': 'is'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'try_statement', 'children': ['79', '88']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'except_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'pass_statement', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'io_fits'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_fitsloader'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '126'], 'value': '-'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'prep_hdu_menu'},{'id': '132', 'type': 'argument_list', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'hdu'},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'hdu_info'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'num_hdu'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '149', 'type': 'expression_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': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '%'},{'id': '158', 'type': 'string', 'children': [], 'value': '"there are %d hdus"'},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '172']},{'id': '165', 'type': 'attribute', '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': 'w'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'numhdu'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '%'},{'id': '174', 'type': 'string', 'children': [], 'value': '"%d"'},{'id': '175', 'type': '()', 'children': ['176']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '188']},{'id': '181', 'type': 'attribute', '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': 'w'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'hdu'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'set_enabled'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '196'], 'value': '>'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'iohelper'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'name_image_from_path'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'idx'"},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': "r'^(.+)\\[(.+)\\]$'"},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '232', 'type': 'if_statement', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'match'},{'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': 'name'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'integer', 'children': [], 'value': '1'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'name_pfx'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'htype'},{'id': '253', 'type': 'None', 'children': []},{'id': '254', 'type': 'if_statement', 'children': ['255', '258']},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'is'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '257', 'type': 'None', 'children': []},{'id': '258', 'type': 'block', 'children': ['259', '273']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '262', 'type': 'call', 'children': ['263', '270']},{'id': '263', 'type': 'attribute', 'children': ['264', '269']},{'id': '264', 'type': 'attribute', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'file_obj'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'hdu_db'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '272', 'type': 'None', 'children': []},{'id': '273', 'type': 'if_statement', 'children': ['274', '277']},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': 'is'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '276', 'type': 'None', 'children': []},{'id': '277', 'type': 'block', 'children': ['278', '288', '296']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'htype'},{'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': 'info'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'htype'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'toc_ent'},{'id': '291', 'type': 'binary_operator', 'children': ['292', '295'], 'value': '%'},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '294', 'type': 'identifier', 'children': [], 'value': '_toc_fmt'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '305']},{'id': '298', 'type': 'attribute', 'children': ['299', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'hdu'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'show_text'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'toc_ent'},{'id': '307', 'type': 'if_statement', 'children': ['308', '313']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '312'], 'value': '!='},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'img_name'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '313', 'type': 'block', 'children': ['314', '320', '326', '334', '416']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'img_name'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '323', 'type': 'list', 'children': ['324', '325'], 'value': '[0, 0]'},{'id': '324', 'type': 'integer', 'children': [], 'value': '0'},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'get_data'},{'id': '333', 'type': 'argument_list', 'children': []},{'id': '334', 'type': 'if_statement', 'children': ['335', '338', '354', '362', '386']},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': 'is'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '337', 'type': 'None', 'children': []},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '346']},{'id': '341', 'type': 'attribute', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'binary_operator', 'children': ['348', '349'], 'value': '%'},{'id': '348', 'type': 'string', 'children': [], 'value': '"Empty data part in HDU %s"'},{'id': '349', 'type': '()', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '354', 'type': 'elif_clause', 'children': ['355', '360']},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': 'in'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'htype'},{'id': '357', 'type': 'tuple', 'children': ['358', '359']},{'id': '358', 'type': 'string', 'children': [], 'value': "'bintablehdu'"},{'id': '359', 'type': 'string', 'children': [], 'value': "'tablehdu'"},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'pass_statement', 'children': []},{'id': '362', 'type': 'elif_clause', 'children': ['363', '369']},{'id': '363', 'type': 'comparison_operator', 'children': ['364', '365'], 'value': 'not'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'htype'},{'id': '365', 'type': 'tuple', 'children': ['366', '367', '368']},{'id': '366', 'type': 'string', 'children': [], 'value': "'imagehdu'"},{'id': '367', 'type': 'string', 'children': [], 'value': "'primaryhdu'"},{'id': '368', 'type': 'string', 'children': [], 'value': "'compimagehdu'"},{'id': '369', 'type': 'block', 'children': ['370']},{'id': '370', 'type': 'expression_statement', 'children': ['371']},{'id': '371', 'type': 'call', 'children': ['372', '377']},{'id': '372', 'type': 'attribute', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'binary_operator', 'children': ['379', '380'], 'value': '%'},{'id': '379', 'type': 'string', 'children': [], 'value': '"HDU %s is not an image (%s)"'},{'id': '380', 'type': 'tuple', 'children': ['381', '385']},{'id': '381', 'type': 'call', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'htype'},{'id': '386', 'type': 'else_clause', 'children': ['387']},{'id': '387', 'type': 'block', 'children': ['388', '396']},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'assignment', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'mddata'},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'get_mddata'},{'id': '395', 'type': 'argument_list', 'children': []},{'id': '396', 'type': 'if_statement', 'children': ['397', '400']},{'id': '397', 'type': 'comparison_operator', 'children': ['398', '399'], 'value': 'is'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'mddata'},{'id': '399', 'type': 'None', 'children': []},{'id': '400', 'type': 'block', 'children': ['401', '410']},{'id': '401', 'type': 'expression_statement', 'children': ['402']},{'id': '402', 'type': 'assignment', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '404', 'type': 'call', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '406', 'type': 'argument_list', 'children': ['407']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'mddata'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'call', 'children': ['412', '415']},{'id': '412', 'type': 'attribute', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '415', 'type': 'argument_list', 'children': []},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'build_naxis'},{'id': '421', 'type': 'argument_list', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'image'} | def redo(self):
image = self.channel.get_current_image()
if image is None:
return True
path = image.get('path', None)
if path is None:
self.fv.show_error(
"Cannot open image: no value for metadata key 'path'")
return
if path.endswith('asdf'):
return True
if path != self.img_path:
self.img_path = path
if self.file_obj is not None:
try:
self.file_obj.close()
except Exception:
pass
self.file_obj = io_fits.get_fitsloader(logger=self.logger)
self.file_obj.open_file(path)
upper = len(self.file_obj) - 1
self.prep_hdu_menu(self.w.hdu, self.file_obj.hdu_info)
self.num_hdu = upper
self.logger.debug("there are %d hdus" % (upper + 1))
self.w.numhdu.set_text("%d" % (upper + 1))
self.w.hdu.set_enabled(len(self.file_obj) > 0)
name = image.get('name', iohelper.name_image_from_path(path))
idx = image.get('idx', None)
match = re.match(r'^(.+)\[(.+)\]$', name)
if match:
name = match.group(1)
self.name_pfx = name
htype = None
if idx is not None:
info = self.file_obj.hdu_db.get(idx, None)
if info is not None:
htype = info.htype.lower()
toc_ent = self._toc_fmt % info
self.w.hdu.show_text(toc_ent)
if self.img_name != name:
self.img_name = name
dims = [0, 0]
data = image.get_data()
if data is None:
self.logger.warning("Empty data part in HDU %s" % (str(idx)))
elif htype in ('bintablehdu', 'tablehdu',):
pass
elif htype not in ('imagehdu', 'primaryhdu', 'compimagehdu'):
self.logger.warning("HDU %s is not an image (%s)" % (
str(idx), htype))
else:
mddata = image.get_mddata()
if mddata is not None:
dims = list(mddata.shape)
dims.reverse()
self.build_naxis(dims, image) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_download_rtd_zip'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rtd_version'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '35', '46', '63', '75', '87', '99', '114', '135', '152', '209', '216', '237']},{'id': '10', 'type': 'if_statement', 'children': ['11', '20']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'toolkit'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'family'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'qt'"},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'concatenated_string', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'Downloaded documentation not compatible with {} '"},{'id': '29', 'type': 'string', 'children': [], 'value': "'UI toolkit browser'"},{'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': 'toolkit'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'family'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'rtd_version'},{'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': 'rtd_version'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_find_rtd_version'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_find_pkg_data_path'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'help.html'"},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '62', 'type': 'string', 'children': [], 'value': "'ginga.doc'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '74', 'type': 'string', 'children': [], 'value': "'index.html'"},{'id': '75', 'type': 'if_statement', 'children': ['76', '84']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '90', 'type': '()', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'https://readthedocs.org/projects/ginga/downloads/htmlzip/'"},{'id': '95', 'type': 'string', 'children': [], 'value': "'{}/'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'rtd_version'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '102', 'type': 'subscript', 'children': ['103', '113']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'urlretrieve'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '111', 'type': 'dictionary_splat', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'with_statement', 'children': ['115', '127']},{'id': '115', 'type': 'with_clause', 'children': ['116']},{'id': '116', 'type': 'with_item', 'children': ['117']},{'id': '117', 'type': 'as_pattern', 'children': ['118', '125']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'local_path'},{'id': '124', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '125', 'type': 'as_pattern_target', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'zf'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'zf'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'extractall'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'subdir'},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'ginga-{}'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'rtd_version'},{'id': '152', 'type': 'for_statement', 'children': ['153', '154', '160']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'subdir'},{'id': '160', 'type': 'block', 'children': ['161', '173']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '164', 'type': 'call', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'subdir'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '173', 'type': 'if_statement', 'children': ['174', '182', '191']},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '182', 'type': 'block', 'children': ['183']},{'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': 'shutil'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'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': 'shutil'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'copytree'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'data_path'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'subdir'},{'id': '216', 'type': 'if_statement', 'children': ['217', '226']},{'id': '217', 'type': 'not_operator', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '224']},{'id': '219', 'type': 'attribute', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'raise_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'string', 'children': [], 'value': "'{} is missing; Ginga doc download failed'"},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'index_html'} | def _download_rtd_zip(rtd_version=None, **kwargs):
if not toolkit.family.startswith('qt'):
raise ValueError('Downloaded documentation not compatible with {} '
'UI toolkit browser'.format(toolkit.family))
if rtd_version is None:
rtd_version = _find_rtd_version()
data_path = os.path.dirname(
_find_pkg_data_path('help.html', package='ginga.doc'))
index_html = os.path.join(data_path, 'index.html')
if os.path.isfile(index_html):
return index_html
url = ('https://readthedocs.org/projects/ginga/downloads/htmlzip/'
'{}/'.format(rtd_version))
local_path = urllib.request.urlretrieve(url, **kwargs)[0]
with zipfile.ZipFile(local_path, 'r') as zf:
zf.extractall(data_path)
subdir = os.path.join(data_path, 'ginga-{}'.format(rtd_version))
for s in os.listdir(subdir):
src = os.path.join(subdir, s)
if os.path.isfile(src):
shutil.copy(src, data_path)
else:
shutil.copytree(src, os.path.join(data_path, s))
shutil.rmtree(subdir)
if not os.path.isfile(index_html):
raise OSError(
'{} is missing; Ginga doc download failed'.format(index_html))
return index_html |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_doc'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'reporthook'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '22', '68', '158']},{'id': '14', 'type': 'import_from_statement', 'children': ['15', '18', '20']},{'id': '15', 'type': 'dotted_name', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ginga'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'GingaPlugin'},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'GlobalPlugin'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'LocalPlugin'},{'id': '22', 'type': 'if_statement', 'children': ['23', '28', '40', '58']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'GlobalPlugin'},{'id': '28', 'type': 'block', 'children': ['29', '33']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'plugin_page'},{'id': '32', 'type': 'string', 'children': [], 'value': "'plugins_global'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '40', 'type': 'elif_clause', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'LocalPlugin'},{'id': '46', 'type': 'block', 'children': ['47', '51']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'plugin_page'},{'id': '50', 'type': 'string', 'children': [], 'value': "'plugins_local'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60', '64']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'plugin_page'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'try_statement', 'children': ['69', '79', '135']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_download_rtd_zip'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'reporthook'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'reporthook'},{'id': '79', 'type': 'except_clause', 'children': ['80', '84']},{'id': '80', 'type': 'as_pattern', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '82', 'type': 'as_pattern_target', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '84', 'type': 'block', 'children': ['85', '89', '120']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '88', 'type': 'string', 'children': [], 'value': "'https://ginga.readthedocs.io/en/latest/'"},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'if_statement', 'children': ['95', '103', '108']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'toolkit'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'family'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': "'qt'"},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '107', 'type': 'None', 'children': []},{'id': '108', 'type': 'else_clause', 'children': ['109']},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'augmented_assignment', 'children': ['112', '113'], 'value': '+='},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "'manual/{}/{}.html'"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'plugin_page'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '120', 'type': 'if_statement', 'children': ['121', '124']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '123', 'type': 'None', 'children': []},{'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': 'logger'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '135', 'type': 'else_clause', 'children': ['136']},{'id': '136', 'type': 'block', 'children': ['137', '141', '151']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pfx'},{'id': '140', 'type': 'string', 'children': [], 'value': "'file:'"},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'{}{}'"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'pfx'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'index_html'},{'id': '151', 'type': 'if_statement', 'children': ['152', '155', '157']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'plugin_name'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': 'ERROR', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '157', 'type': 'block', 'children': [], 'value': ''},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'url'} | def get_doc(logger=None, plugin=None, reporthook=None):
from ginga.GingaPlugin import GlobalPlugin, LocalPlugin
if isinstance(plugin, GlobalPlugin):
plugin_page = 'plugins_global'
plugin_name = str(plugin)
elif isinstance(plugin, LocalPlugin):
plugin_page = 'plugins_local'
plugin_name = str(plugin)
else:
plugin_page = None
plugin_name = None
try:
index_html = _download_rtd_zip(reporthook=reporthook)
except Exception as e:
url = 'https://ginga.readthedocs.io/en/latest/'
if plugin_name is not None:
if toolkit.family.startswith('qt'):
url = None
else:
url += 'manual/{}/{}.html'.format(plugin_page, plugin_name)
if logger is not None:
logger.error(str(e))
else:
pfx = 'file:'
url = '{}{}'.format(pfx, index_html)
if plugin_name is not None:
url += '
return url |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'redo'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '15', '27', '35', '43', '54', '67', '73', '99', '321', '330', '337']},{'id': '8', 'type': 'if_statement', 'children': ['9', '13']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'gui_up'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'mod_only'},{'id': '18', 'type': 'call', 'children': ['19', '26']},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'modified_only'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get_state'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Bunch'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'caselessDict'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'treeview'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '52']},{'id': '45', 'type': 'attribute', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "''"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'fv'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_channel'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'chname'},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'return_statement', 'children': []},{'id': '73', 'type': 'if_statement', 'children': ['74', '75', '89']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'mod_only'},{'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': 'all_keys'},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'datasrc'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '88', 'type': 'string', 'children': [], 'value': "'alpha'"},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_image_names'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '102', 'type': 'block', 'children': ['103', '112', '121', '130', '139', '199', '204', '212']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'iminfo'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_image_info'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'iminfo'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'iminfo'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'idx'"},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'iminfo'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'time_modified'"},{'id': '139', 'type': 'if_statement', 'children': ['140', '143', '152']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'is'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '142', 'type': 'None', 'children': []},{'id': '143', 'type': 'block', 'children': ['144', '148']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'is_fits'},{'id': '151', 'type': 'True', 'children': []},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154', '165', '178', '186', '190']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'infile'},{'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': 'os'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'infile_ext'},{'id': '168', 'type': 'subscript', 'children': ['169', '177']},{'id': '169', 'type': 'call', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'infile_ext'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'infile_ext'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'is_fits'},{'id': '189', 'type': 'False', 'children': []},{'id': '190', 'type': 'if_statement', 'children': ['191', '194']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'in'},{'id': '192', 'type': 'string', 'children': [], 'value': "'fit'"},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'infile_ext'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'is_fits'},{'id': '198', 'type': 'True', 'children': []},{'id': '199', 'type': 'if_statement', 'children': ['200', '202']},{'id': '200', 'type': 'not_operator', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'is_fits'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'continue_statement', 'children': []},{'id': '204', 'type': 'if_statement', 'children': ['205', '210']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '207'], 'value': 'and'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'mod_only'},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'is'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'continue_statement', 'children': []},{'id': '212', 'type': 'if_statement', 'children': ['213', '216', '263']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'in'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'if_statement', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'is'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '220', 'type': 'None', 'children': []},{'id': '221', 'type': 'block', 'children': ['222', '233', '244']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '231']},{'id': '224', 'type': 'attribute', 'children': ['225', '230']},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'elist'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '251']},{'id': '246', 'type': 'attribute', 'children': ['247', '250']},{'id': '247', 'type': 'subscript', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'MODEXT'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': "';'"},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '258', 'type': 'argument_list', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': '_format_extname'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'elist'},{'id': '263', 'type': 'else_clause', 'children': ['264']},{'id': '264', 'type': 'block', 'children': ['265', '299']},{'id': '265', 'type': 'if_statement', 'children': ['266', '269', '280']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '268'], 'value': 'is'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '268', 'type': 'None', 'children': []},{'id': '269', 'type': 'block', 'children': ['270', '274']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '273', 'type': 'string', 'children': [], 'value': "''"},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '279', 'type': 'argument_list', 'children': []},{'id': '280', 'type': 'else_clause', 'children': ['281']},{'id': '281', 'type': 'block', 'children': ['282', '291']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '288', 'type': 'identifier', 'children': [], 'value': '_format_extname'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'list', 'children': ['298'], 'value': '[idx]'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '304']},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'Bunch'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'Bunch'},{'id': '308', 'type': 'argument_list', 'children': ['309', '312', '315', '318']},{'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'IMAGE'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'MODEXT'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'extlist'},{'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '328']},{'id': '323', 'type': 'attribute', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'treeview'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'set_tree'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'treedict'},{'id': '337', 'type': 'if_statement', 'children': ['338', '341', '353']},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '340'], 'value': '=='},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '340', 'type': 'integer', 'children': [], 'value': '0'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '351']},{'id': '344', 'type': 'attribute', 'children': ['345', '350']},{'id': '345', 'type': 'attribute', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'set_text'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'string', 'children': [], 'value': "'Nothing available for saving'"},{'id': '353', 'type': 'elif_clause', 'children': ['354', '365']},{'id': '354', 'type': 'comparison_operator', 'children': ['355', '356'], 'value': '<'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'n_rows'},{'id': '356', 'type': 'call', 'children': ['357', '362']},{'id': '357', 'type': 'attribute', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '362', 'type': 'argument_list', 'children': ['363', '364']},{'id': '363', 'type': 'string', 'children': [], 'value': "'max_rows_for_col_resize'"},{'id': '364', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '365', 'type': 'block', 'children': ['366', '374']},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '373']},{'id': '368', 'type': 'attribute', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'treeview'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'set_optimal_column_widths'},{'id': '373', 'type': 'argument_list', 'children': []},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'call', 'children': ['376', '381']},{'id': '376', 'type': 'attribute', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'call', 'children': ['383', '386']},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'string', 'children': [], 'value': "'Resized columns for {0} row(s)'"},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '386', 'type': 'argument_list', 'children': ['387']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'n_rows'} | def redo(self, *args):
if not self.gui_up:
return
mod_only = self.w.modified_only.get_state()
treedict = Bunch.caselessDict()
self.treeview.clear()
self.w.status.set_text('')
channel = self.fv.get_channel(self.chname)
if channel is None:
return
if mod_only:
all_keys = channel.datasrc.keys(sort='alpha')
else:
all_keys = channel.get_image_names()
for key in all_keys:
iminfo = channel.get_image_info(key)
path = iminfo.get('path')
idx = iminfo.get('idx')
t = iminfo.get('time_modified')
if path is None:
infile = key
is_fits = True
else:
infile = os.path.basename(path)
infile_ext = os.path.splitext(path)[1]
infile_ext = infile_ext.lower()
is_fits = False
if 'fit' in infile_ext:
is_fits = True
if not is_fits:
continue
if mod_only and t is None:
continue
if infile in treedict:
if t is not None:
treedict[infile].extlist.add(idx)
elist = sorted(treedict[infile].extlist)
treedict[infile].MODEXT = ';'.join(
map(self._format_extname, elist))
else:
if t is None:
s = ''
extlist = set()
else:
s = self._format_extname(idx)
extlist = set([idx])
treedict[infile] = Bunch.Bunch(
IMAGE=infile, MODEXT=s, extlist=extlist, path=path)
self.treeview.set_tree(treedict)
n_rows = len(treedict)
if n_rows == 0:
self.w.status.set_text('Nothing available for saving')
elif n_rows < self.settings.get('max_rows_for_col_resize', 5000):
self.treeview.set_optimal_column_widths()
self.logger.debug('Resized columns for {0} row(s)'.format(n_rows)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_imload'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '7', 'type': 'block', 'children': ['8', '16', '27', '35', '46', '59', '63', '170', '323', '360', '373', '381', '396']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'enc'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mimetypes'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'guess_type'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '27', 'type': 'if_statement', 'children': ['28', '30']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'typ'},{'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': 'typ'},{'id': '34', 'type': 'string', 'children': [], 'value': "'image/jpeg'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'subtyp'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': '"MIME type is %s/%s"'},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'subtyp'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '62', 'type': 'False', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '70']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '66'], 'value': 'and'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'have_opencv'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'subtyp'},{'id': '68', 'type': 'list', 'children': ['69'], 'value': "['gif']"},{'id': '69', 'type': 'string', 'children': [], 'value': "'gif'"},{'id': '70', 'type': 'block', 'children': ['71', '75', '91']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '74', 'type': 'string', 'children': [], 'value': "'opencv'"},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cv2'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'imread'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '+'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cv2'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'IMREAD_ANYDEPTH'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cv2'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'IMREAD_ANYCOLOR'},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '100', '129', '137', '143', '149']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '99', 'type': 'True', 'children': []},{'id': '100', 'type': 'if_statement', 'children': ['101', '117']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '110'], 'value': 'and'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '109'], 'value': '>='},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '109', 'type': 'integer', 'children': [], 'value': '3'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '116'], 'value': '>='},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '115', 'type': 'integer', 'children': [], 'value': '2'},{'id': '116', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'data_np'},{'id': '121', 'type': 'subscript', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '123', 'type': 'ellipsis', 'children': [], 'value': '...'},{'id': '124', 'type': 'slice', 'children': ['125', '126', '127']},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'unary_operator', 'children': ['128'], 'value': '-'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'piexif_getexif'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '141', 'type': 'string', 'children': [], 'value': "'Orientation'"},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '147', 'type': 'string', 'children': [], 'value': "'Image Orientation'"},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'if_statement', 'children': ['150', '157']},{'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': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'clr_mgr'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'can_profile'},{'id': '156', 'type': 'argument_list', 'children': []},{'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': 'data_np'},{'id': '161', 'type': 'call', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'clr_mgr'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'profile_to_working_numpy'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '170', 'type': 'if_statement', 'children': ['171', '175']},{'id': '171', 'type': 'boolean_operator', 'children': ['172', '174'], 'value': 'and'},{'id': '172', 'type': 'not_operator', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'have_pil'},{'id': '175', 'type': 'block', 'children': ['176', '180', '189', '284', '305', '314']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '179', 'type': 'string', 'children': [], 'value': "'PIL'"},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'PILimage'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '189', 'type': 'try_statement', 'children': ['190', '263']},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '197', '237', '252']},{'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': 'image'},{'id': '196', 'type': 'string', 'children': [], 'value': "'_getexif'"},{'id': '197', 'type': 'block', 'children': ['198', '206']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_getexif'},{'id': '205', 'type': 'argument_list', 'children': []},{'id': '206', 'type': 'if_statement', 'children': ['207', '210']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': 'is'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'for_statement', 'children': ['212', '215', '220']},{'id': '212', 'type': 'pattern_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'block', 'children': ['221', '231']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'kwd'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'TAGS'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'kwd'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '237', 'type': 'elif_clause', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'have_exif'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'piexif_getexif'},{'id': '245', 'type': 'argument_list', 'children': ['246', '251']},{'id': '246', 'type': 'subscript', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '250', 'type': 'string', 'children': [], 'value': '"exif"'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'string', 'children': [], 'value': '"Please install \'piexif\' module to get image metadata"'},{'id': '263', 'type': 'except_clause', 'children': ['264', '268']},{'id': '264', 'type': 'as_pattern', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '266', 'type': 'as_pattern_target', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '276']},{'id': '271', 'type': 'attribute', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '%'},{'id': '278', 'type': 'string', 'children': [], 'value': '"Failed to get image metadata: %s"'},{'id': '279', 'type': '()', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '284', 'type': 'if_statement', 'children': ['285', '292']},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'clr_mgr'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'can_profile'},{'id': '291', 'type': 'argument_list', 'children': []},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '296', 'type': 'call', 'children': ['297', '302']},{'id': '297', 'type': 'attribute', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'clr_mgr'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'profile_to_working_pil'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'kwds'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '314', 'type': 'if_statement', 'children': ['315', '318']},{'id': '315', 'type': 'comparison_operator', 'children': ['316', '317'], 'value': 'is'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '317', 'type': 'None', 'children': []},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '322', 'type': 'True', 'children': []},{'id': '323', 'type': 'if_statement', 'children': ['324', '339']},{'id': '324', 'type': '()', 'children': ['325']},{'id': '325', 'type': 'boolean_operator', 'children': ['326', '333'], 'value': 'and'},{'id': '326', 'type': 'boolean_operator', 'children': ['327', '329'], 'value': 'and'},{'id': '327', 'type': 'not_operator', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '329', 'type': '()', 'children': ['330']},{'id': '330', 'type': 'comparison_operator', 'children': ['331', '332'], 'value': '=='},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '332', 'type': 'string', 'children': [], 'value': "'image'"},{'id': '333', 'type': '()', 'children': ['334']},{'id': '334', 'type': 'comparison_operator', 'children': ['335', '336'], 'value': 'in'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'subtyp'},{'id': '336', 'type': 'tuple', 'children': ['337', '338']},{'id': '337', 'type': 'string', 'children': [], 'value': "'x-portable-pixmap'"},{'id': '338', 'type': 'string', 'children': [], 'value': "'x-portable-greymap'"},{'id': '339', 'type': 'block', 'children': ['340', '344', '351']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '343', 'type': 'string', 'children': [], 'value': "'built-in'"},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'assignment', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'open_ppm'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '351', 'type': 'if_statement', 'children': ['352', '355']},{'id': '352', 'type': 'comparison_operator', 'children': ['353', '354'], 'value': 'is'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'data_np'},{'id': '354', 'type': 'None', 'children': []},{'id': '355', 'type': 'block', 'children': ['356']},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'assignment', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '359', 'type': 'True', 'children': []},{'id': '360', 'type': 'if_statement', 'children': ['361', '363']},{'id': '361', 'type': 'not_operator', 'children': ['362']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'data_loaded'},{'id': '363', 'type': 'block', 'children': ['364']},{'id': '364', 'type': 'raise_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'ImageError'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '%'},{'id': '369', 'type': 'string', 'children': [], 'value': '"No way to load image format \'%s/%s\'"'},{'id': '370', 'type': 'tuple', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'subtyp'},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '380', 'type': 'argument_list', 'children': []},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'call', 'children': ['383', '388']},{'id': '383', 'type': 'attribute', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '388', 'type': 'argument_list', 'children': ['389']},{'id': '389', 'type': 'binary_operator', 'children': ['390', '391'], 'value': '%'},{'id': '390', 'type': 'string', 'children': [], 'value': '"loading (%s) time %.4f sec"'},{'id': '391', 'type': 'tuple', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'means'},{'id': '393', 'type': 'binary_operator', 'children': ['394', '395'], 'value': '-'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'end_time'},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '396', 'type': 'return_statement', 'children': ['397']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'data_np'} | def _imload(self, filepath, kwds):
start_time = time.time()
typ, enc = mimetypes.guess_type(filepath)
if not typ:
typ = 'image/jpeg'
typ, subtyp = typ.split('/')
self.logger.debug("MIME type is %s/%s" % (typ, subtyp))
data_loaded = False
if have_opencv and subtyp not in ['gif']:
means = 'opencv'
data_np = cv2.imread(filepath,
cv2.IMREAD_ANYDEPTH + cv2.IMREAD_ANYCOLOR)
if data_np is not None:
data_loaded = True
if len(data_np.shape) >= 3 and data_np.shape[2] >= 3:
data_np = data_np[..., :: -1]
self.piexif_getexif(filepath, kwds)
kwds['Orientation'] = 1
kwds['Image Orientation'] = 1
if self.clr_mgr.can_profile():
data_np = self.clr_mgr.profile_to_working_numpy(data_np, kwds)
if not data_loaded and have_pil:
means = 'PIL'
image = PILimage.open(filepath)
try:
if hasattr(image, '_getexif'):
info = image._getexif()
if info is not None:
for tag, value in info.items():
kwd = TAGS.get(tag, tag)
kwds[kwd] = value
elif have_exif:
self.piexif_getexif(image.info["exif"], kwds)
else:
self.logger.warning("Please install 'piexif' module to get image metadata")
except Exception as e:
self.logger.warning("Failed to get image metadata: %s" % (str(e)))
if self.clr_mgr.can_profile():
image = self.clr_mgr.profile_to_working_pil(image, kwds)
data_np = np.array(image)
if data_np is not None:
data_loaded = True
if (not data_loaded and (typ == 'image') and
(subtyp in ('x-portable-pixmap', 'x-portable-greymap'))):
means = 'built-in'
data_np = open_ppm(filepath)
if data_np is not None:
data_loaded = True
if not data_loaded:
raise ImageError("No way to load image format '%s/%s'" % (
typ, subtyp))
end_time = time.time()
self.logger.debug("loading (%s) time %.4f sec" % (
means, end_time - start_time))
return data_np |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_coord_system_name'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '5', 'type': 'block', 'children': ['6', '77', '87', '92', '102', '107', '117', '197', '207', '212', '222', '227', '237', '242', '252', '257']},{'id': '6', 'type': 'try_statement', 'children': ['7', '22']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '11', 'type': 'call', 'children': ['12', '21']},{'id': '12', 'type': 'attribute', 'children': ['13', '20']},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '17', 'type': 'string', 'children': [], 'value': "'CTYPE1'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'except_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'try_statement', 'children': ['26', '72']},{'id': '26', 'type': 'block', 'children': ['27', '33', '66']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ra'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '32', 'type': 'string', 'children': [], 'value': "'RA'"},{'id': '33', 'type': 'try_statement', 'children': ['34', '59']},{'id': '34', 'type': 'block', 'children': ['35', '44']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'equinox'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '43', 'type': 'string', 'children': [], 'value': "'EQUINOX'"},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '53']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'equinox'},{'id': '47', 'type': 'float', 'children': [], 'value': '1984.0'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '52', 'type': 'string', 'children': [], 'value': "'FK4'"},{'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': 'radecsys'},{'id': '58', 'type': 'string', 'children': [], 'value': "'FK5'"},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'radecsys'},{'id': '65', 'type': 'string', 'children': [], 'value': "'ICRS'"},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'except_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'raw'"},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "r'^GLON\\-.*$'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '87', 'type': 'if_statement', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': "'galactic'"},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': "r'^ELON\\-.*$'"},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '102', 'type': 'if_statement', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'ecliptic'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "r'^RA\\-\\-\\-.*$'"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '117', 'type': 'if_statement', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '119', 'type': 'block', 'children': ['120', '124', '183', '191']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'hdkey'},{'id': '123', 'type': 'string', 'children': [], 'value': "'RADECSYS'"},{'id': '124', 'type': 'try_statement', 'children': ['125', '132']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'hdkey'},{'id': '132', 'type': 'except_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'try_statement', 'children': ['136', '147']},{'id': '136', 'type': 'block', 'children': ['137', '141']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'hdkey'},{'id': '140', 'type': 'string', 'children': [], 'value': "'RADESYS'"},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'hdkey'},{'id': '147', 'type': 'except_clause', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'try_statement', 'children': ['151', '176']},{'id': '151', 'type': 'block', 'children': ['152', '161']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'equinox'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '160', 'type': 'string', 'children': [], 'value': "'EQUINOX'"},{'id': '161', 'type': 'if_statement', 'children': ['162', '165', '170']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '<'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'equinox'},{'id': '164', 'type': 'float', 'children': [], 'value': '1984.0'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '169', 'type': 'string', 'children': [], 'value': "'FK4'"},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '175', 'type': 'string', 'children': [], 'value': "'FK5'"},{'id': '176', 'type': 'except_clause', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'radecsys'},{'id': '182', 'type': 'string', 'children': [], 'value': "'ICRS'"},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'radecsys'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "r'^HPLN\\-.*$'"},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '207', 'type': 'if_statement', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'string', 'children': [], 'value': "'helioprojective'"},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "r'^HGLT\\-.*$'"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '222', 'type': 'if_statement', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'return_statement', 'children': ['226']},{'id': '226', 'type': 'string', 'children': [], 'value': "'heliographicstonyhurst'"},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': "r'^PIXEL$'"},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '237', 'type': 'if_statement', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'string', 'children': [], 'value': "'pixel'"},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251']},{'id': '250', 'type': 'string', 'children': [], 'value': "r'^LINEAR$'"},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '252', 'type': 'if_statement', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'string', 'children': [], 'value': "'pixel'"},{'id': '257', 'type': 'return_statement', 'children': ['258']},{'id': '258', 'type': 'string', 'children': [], 'value': "'icrs'"} | def get_coord_system_name(header):
try:
ctype = header['CTYPE1'].strip().upper()
except KeyError:
try:
ra = header['RA']
try:
equinox = float(header['EQUINOX'])
if equinox < 1984.0:
radecsys = 'FK4'
else:
radecsys = 'FK5'
except KeyError:
radecsys = 'ICRS'
return radecsys.lower()
except KeyError:
return 'raw'
match = re.match(r'^GLON\-.*$', ctype)
if match:
return 'galactic'
match = re.match(r'^ELON\-.*$', ctype)
if match:
return 'ecliptic'
match = re.match(r'^RA\-\-\-.*$', ctype)
if match:
hdkey = 'RADECSYS'
try:
radecsys = header[hdkey]
except KeyError:
try:
hdkey = 'RADESYS'
radecsys = header[hdkey]
except KeyError:
try:
equinox = float(header['EQUINOX'])
if equinox < 1984.0:
radecsys = 'FK4'
else:
radecsys = 'FK5'
except KeyError:
radecsys = 'ICRS'
radecsys = radecsys.strip()
return radecsys.lower()
match = re.match(r'^HPLN\-.*$', ctype)
if match:
return 'helioprojective'
match = re.match(r'^HGLT\-.*$', ctype)
if match:
return 'heliographicstonyhurst'
match = re.match(r'^PIXEL$', ctype)
if match:
return 'pixel'
match = re.match(r'^LINEAR$', ctype)
if match:
return 'pixel'
return 'icrs' |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_do_info'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '6', 'type': 'block', 'children': ['7', '43', '58', '64', '76', '86', '97', '119', '136']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': '_filter_components'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'compdetails'},{'id': '11', 'type': 'block', 'children': ['12', '16', '41']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '25']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'compdetails'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '34']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"is_active"'},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '55'], 'value': 'or'},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '52'], 'value': 'or'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'component_owners'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '61', 'type': 'list', 'children': ['62', '63'], 'value': '["name", "id"]'},{'id': '62', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '63', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fastcomponents'},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'and'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '72', 'type': 'not_operator', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'active_components'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'versions'},{'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': 'include_fields'},{'id': '84', 'type': 'list', 'children': ['85'], 'value': '["versions"]'},{'id': '85', 'type': 'string', 'children': [], 'value': '"versions"'},{'id': '86', 'type': 'if_statement', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'component_owners'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '+='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '94', 'type': 'list', 'children': ['95', '96'], 'value': '[\n "components.default_assigned_to",\n "components.name",\n ]'},{'id': '95', 'type': 'string', 'children': [], 'value': '"components.default_assigned_to"'},{'id': '96', 'type': 'string', 'children': [], 'value': '"components.name"'},{'id': '97', 'type': 'if_statement', 'children': ['98', '113']},{'id': '98', 'type': '()', 'children': ['99']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'and'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'active_components'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'list_comprehension', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'in'},{'id': '108', 'type': 'string', 'children': [], 'value': '"components"'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'augmented_assignment', 'children': ['116', '117'], 'value': '+='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '117', 'type': 'list', 'children': ['118'], 'value': '["components.is_active"]'},{'id': '118', 'type': 'string', 'children': [], 'value': '"components.is_active"'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'refresh_products'},{'id': '124', 'type': 'argument_list', 'children': ['125', '133']},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '132'], 'value': 'or'},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '130'], 'value': 'and'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '130', 'type': 'list', 'children': ['131'], 'value': '[productname]'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140', '163', '183', '212', '243']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'products'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '157']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'list_comprehension', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '149', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'getproducts'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '163', 'type': 'elif_clause', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'fastcomponents'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '177']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'getcomponents'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '183', 'type': 'elif_clause', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '187', 'type': 'block', 'children': ['188', '197']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'getcomponentsdetails'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '197', 'type': 'for_statement', 'children': ['198', '199', '206']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_filter_components'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '212', 'type': 'elif_clause', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '216', 'type': 'block', 'children': ['217', '227']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'proddict'},{'id': '220', 'type': 'subscript', 'children': ['221', '226']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'getproducts'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'for_statement', 'children': ['228', '229', '232']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'proddict'},{'id': '231', 'type': 'string', 'children': [], 'value': "'versions'"},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'to_encoding'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '242', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '243', 'type': 'elif_clause', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'component_owners'},{'id': '247', 'type': 'block', 'children': ['248', '257']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'bz'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'getcomponentsdetails'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'productname'},{'id': '257', 'type': 'for_statement', 'children': ['258', '259', '266']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'c'},{'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', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': '_filter_components'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'to_encoding'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '%'},{'id': '275', 'type': 'string', 'children': [], 'value': 'u"%s: %s"'},{'id': '276', 'type': 'tuple', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '278', 'type': 'subscript', 'children': ['279', '282']},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '282', 'type': 'string', 'children': [], 'value': "'default_assigned_to'"} | def _do_info(bz, opt):
def _filter_components(compdetails):
ret = {}
for k, v in compdetails.items():
if v.get("is_active", True):
ret[k] = v
return ret
productname = (opt.components or opt.component_owners or opt.versions)
include_fields = ["name", "id"]
fastcomponents = (opt.components and not opt.active_components)
if opt.versions:
include_fields += ["versions"]
if opt.component_owners:
include_fields += [
"components.default_assigned_to",
"components.name",
]
if (opt.active_components and
any(["components" in i for i in include_fields])):
include_fields += ["components.is_active"]
bz.refresh_products(names=productname and [productname] or None,
include_fields=include_fields)
if opt.products:
for name in sorted([p["name"] for p in bz.getproducts()]):
print(name)
elif fastcomponents:
for name in sorted(bz.getcomponents(productname)):
print(name)
elif opt.components:
details = bz.getcomponentsdetails(productname)
for name in sorted(_filter_components(details)):
print(name)
elif opt.versions:
proddict = bz.getproducts()[0]
for v in proddict['versions']:
print(to_encoding(v["name"]))
elif opt.component_owners:
details = bz.getcomponentsdetails(productname)
for c in sorted(_filter_components(details)):
print(to_encoding(u"%s: %s" % (c,
details[c]['default_assigned_to']))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'login'},{'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': 'user'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'restrict_login'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '25', '34', '43', '54', '65', '75']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"cannot login when using an API key"'},{'id': '25', 'type': 'if_statement', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '34', 'type': 'if_statement', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '43', 'type': 'if_statement', 'children': ['44', '48']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': '"missing username"'},{'id': '54', 'type': 'if_statement', 'children': ['55', '59']},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'raise_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': '"missing password"'},{'id': '65', 'type': 'if_statement', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'restrict_login'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': '"logging in with restrict_login=True"'},{'id': '75', 'type': 'try_statement', 'children': ['76', '110']},{'id': '76', 'type': 'block', 'children': ['77', '92', '98', '108']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_login'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88', '91']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'restrict_login'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '97', 'type': 'string', 'children': [], 'value': "''"},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '"login successful for user=%s"'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '110', 'type': 'except_clause', 'children': ['111', '115']},{'id': '111', 'type': 'as_pattern', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Fault'},{'id': '113', 'type': 'as_pattern_target', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'raise_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'BugzillaError'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '%'},{'id': '121', 'type': 'string', 'children': [], 'value': '"Login failed: %s"'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'faultString'} | def login(self, user=None, password=None, restrict_login=None):
if self.api_key:
raise ValueError("cannot login when using an API key")
if user:
self.user = user
if password:
self.password = password
if not self.user:
raise ValueError("missing username")
if not self.password:
raise ValueError("missing password")
if restrict_login:
log.info("logging in with restrict_login=True")
try:
ret = self._login(self.user, self.password, restrict_login)
self.password = ''
log.info("login successful for user=%s", self.user)
return ret
except Fault as e:
raise BugzillaError("Login failed: %s" % str(e.faultString)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_include_fields'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '8', 'type': 'block', 'children': ['9', '56', '60', '113', '130']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_convert_fields'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '13', 'type': 'block', 'children': ['14', '20', '54']},{'id': '14', 'type': 'if_statement', 'children': ['15', '17']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '20', 'type': 'for_statement', 'children': ['21', '24', '29']},{'id': '21', 'type': 'pattern_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'oldname'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_get_api_aliases'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'oldname'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '34', 'type': 'block', 'children': ['35', '42']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'oldname'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'newname'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_in'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '59', 'type': 'dictionary', 'children': []},{'id': '60', 'type': 'if_statement', 'children': ['61', '68']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_check_version'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'integer', 'children': [], 'value': '4'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'block', 'children': ['69', '97']},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '71', 'type': 'block', 'children': ['72', '79', '91']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_convert_fields'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'not'},{'id': '81', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'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': 'include_fields'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': '"id"'},{'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': 'ret'},{'id': '95', 'type': 'string', 'children': [], 'value': '"include_fields"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '97', 'type': 'if_statement', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '99', 'type': 'block', 'children': ['100', '107']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_convert_fields'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'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': 'ret'},{'id': '111', 'type': 'string', 'children': [], 'value': '"exclude_fields"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_supports_getbug_extra_fields'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '125', 'type': 'string', 'children': [], 'value': '"extra_fields"'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_convert_fields'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ret'} | def _process_include_fields(self, include_fields, exclude_fields,
extra_fields):
def _convert_fields(_in):
if not _in:
return _in
for newname, oldname in self._get_api_aliases():
if oldname in _in:
_in.remove(oldname)
if newname not in _in:
_in.append(newname)
return _in
ret = {}
if self._check_version(4, 0):
if include_fields:
include_fields = _convert_fields(include_fields)
if "id" not in include_fields:
include_fields.append("id")
ret["include_fields"] = include_fields
if exclude_fields:
exclude_fields = _convert_fields(exclude_fields)
ret["exclude_fields"] = exclude_fields
if self._supports_getbug_extra_fields:
if extra_fields:
ret["extra_fields"] = _convert_fields(extra_fields)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_getbugs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'permissive'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '21', '25', '51', '62', '68', '75', '84', '98', '111', '158', '162', '219']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'oldidlist'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'oldidlist'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'try_statement', 'children': ['30', '41']},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '41', 'type': 'except_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '61'], 'value': 'or'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'augmented_assignment', 'children': ['64', '65'], 'value': '+='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_getbug_extra_fields'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'getbugdata'},{'id': '71', 'type': 'dictionary', 'children': ['72']},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '"ids"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '75', 'type': 'if_statement', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'permissive'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'getbugdata'},{'id': '82', 'type': 'string', 'children': [], 'value': '"permissive"'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'getbugdata'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_process_include_fields'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'include_fields'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'exclude_fields'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'extra_fields'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '101', 'type': 'call', 'children': ['102', '109']},{'id': '102', 'type': 'attribute', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_proxy'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Bug'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'getbugdata'},{'id': '111', 'type': 'if_statement', 'children': ['112', '119', '137']},{'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': '_check_version'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'integer', 'children': [], 'value': '4'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bugdict'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'list_comprehension', 'children': ['127', '132']},{'id': '127', 'type': 'tuple', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '130', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '136', 'type': 'string', 'children': [], 'value': "'bugs'"},{'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': 'bugdict'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'list_comprehension', 'children': ['146', '153']},{'id': '146', 'type': 'tuple', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '149', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '152', 'type': 'string', 'children': [], 'value': "'internals'"},{'id': '153', 'type': 'for_in_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '157', 'type': 'string', 'children': [], 'value': "'bugs'"},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '161', 'type': 'list', 'children': [], 'value': '[]'},{'id': '162', 'type': 'for_statement', 'children': ['163', '164', '165']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '165', 'type': 'block', 'children': ['166', '170', '212']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '169', 'type': 'None', 'children': []},{'id': '170', 'type': 'if_statement', 'children': ['171', '174', '181']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'in'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'bugdict'},{'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': 'found'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'bugdict'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'else_clause', 'children': ['182']},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'for_statement', 'children': ['184', '185', '190']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'valdict'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'bugdict'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'if_statement', 'children': ['192', '206']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'in'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': '_listify'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'valdict'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'string', 'children': [], 'value': '"alias"'},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'block', 'children': ['207', '211']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'valdict'},{'id': '211', 'type': 'break_statement', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '219', 'type': 'return_statement', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'ret'} | def _getbugs(self, idlist, permissive,
include_fields=None, exclude_fields=None, extra_fields=None):
oldidlist = idlist
idlist = []
for i in oldidlist:
try:
idlist.append(int(i))
except ValueError:
idlist.append(i)
extra_fields = self._listify(extra_fields or [])
extra_fields += self._getbug_extra_fields
getbugdata = {"ids": idlist}
if permissive:
getbugdata["permissive"] = 1
getbugdata.update(self._process_include_fields(
include_fields, exclude_fields, extra_fields))
r = self._proxy.Bug.get(getbugdata)
if self._check_version(4, 0):
bugdict = dict([(b['id'], b) for b in r['bugs']])
else:
bugdict = dict([(b['id'], b['internals']) for b in r['bugs']])
ret = []
for i in idlist:
found = None
if i in bugdict:
found = bugdict[i]
else:
for valdict in bugdict.values():
if i in self._listify(valdict.get("alias", None)):
found = valdict
break
ret.append(found)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'attachfile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attachfile'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '44', '60', '76', '92', '108', '114', '122', '143', '152', '163', '189', '227', '240', '273', '293']},{'id': '11', 'type': 'if_statement', 'children': ['12', '17', '26', '37']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'attachfile'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'attachfile'},{'id': '25', 'type': 'string', 'children': [], 'value': '"rb"'},{'id': '26', 'type': 'elif_clause', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'attachfile'},{'id': '31', 'type': 'string', 'children': [], 'value': "'read'"},{'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': 'f'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'attachfile'},{'id': '37', 'type': 'else_clause', 'children': ['38']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '"attachfile must be filename or file-like object"'},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'string', 'children': [], 'value': '"contenttype"'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '53', 'type': 'string', 'children': [], 'value': '"content_type"'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"contenttype"'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'string', 'children': [], 'value': '"ispatch"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '69', 'type': 'string', 'children': [], 'value': '"is_patch"'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': '"ispatch"'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'string', 'children': [], 'value': '"isprivate"'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '85', 'type': 'string', 'children': [], 'value': '"is_private"'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"isprivate"'},{'id': '92', 'type': 'if_statement', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'},{'id': '94', 'type': 'string', 'children': [], 'value': '"filename"'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '101', 'type': 'string', 'children': [], 'value': '"file_name"'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': '"filename"'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '112', 'type': 'string', 'children': [], 'value': "'summary'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'if_statement', 'children': ['123', '129']},{'id': '123', 'type': 'not_operator', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'getpreferredencoding'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '147', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'Binary'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '156', 'type': 'string', 'children': [], 'value': "'ids'"},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_listify'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'idlist'},{'id': '163', 'type': 'if_statement', 'children': ['164', '173']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '168'], 'value': 'and'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'not'},{'id': '166', 'type': 'string', 'children': [], 'value': "'file_name'"},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '172', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '178', 'type': 'string', 'children': [], 'value': "'file_name'"},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '189', 'type': 'if_statement', 'children': ['190', '193']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'not'},{'id': '191', 'type': 'string', 'children': [], 'value': "'content_type'"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '193', 'type': 'block', 'children': ['194', '198', '219']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '197', 'type': 'None', 'children': []},{'id': '198', 'type': 'if_statement', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '201', 'type': 'string', 'children': [], 'value': "'file_name'"},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '206', 'type': 'subscript', 'children': ['207', '218']},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'mimetypes'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'guess_type'},{'id': '211', 'type': 'argument_list', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '214', 'type': 'string', 'children': [], 'value': "'file_name'"},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '217', 'type': 'False', 'children': []},{'id': '218', 'type': 'integer', 'children': [], 'value': '0'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '224']},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '223', 'type': 'string', 'children': [], 'value': "'content_type'"},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '226'], 'value': 'or'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '226', 'type': 'string', 'children': [], 'value': "'application/octet-stream'"},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '230', 'type': 'call', 'children': ['231', '238']},{'id': '231', 'type': 'attribute', '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': '_proxy'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'Bug'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'add_attachment'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '240', 'type': 'if_statement', 'children': ['241', '244', '262']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': 'in'},{'id': '242', 'type': 'string', 'children': [], 'value': '"attachments"'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '248', 'type': 'list_comprehension', 'children': ['249', '253']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '253', 'type': 'for_in_clause', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '259', 'type': 'string', 'children': [], 'value': '"attachments"'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'elif_clause', 'children': ['263', '266']},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '265'], 'value': 'in'},{'id': '264', 'type': 'string', 'children': [], 'value': '"ids"'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '272', 'type': 'string', 'children': [], 'value': '"ids"'},{'id': '273', 'type': 'if_statement', 'children': ['274', '286']},{'id': '274', 'type': 'boolean_operator', 'children': ['275', '280'], 'value': 'and'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '277', 'type': 'argument_list', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '285'], 'value': '=='},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '292', 'type': 'integer', 'children': [], 'value': '0'},{'id': '293', 'type': 'return_statement', 'children': ['294']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'ret'} | def attachfile(self, idlist, attachfile, description, **kwargs):
if isinstance(attachfile, str):
f = open(attachfile, "rb")
elif hasattr(attachfile, 'read'):
f = attachfile
else:
raise TypeError("attachfile must be filename or file-like object")
if "contenttype" in kwargs:
kwargs["content_type"] = kwargs.pop("contenttype")
if "ispatch" in kwargs:
kwargs["is_patch"] = kwargs.pop("ispatch")
if "isprivate" in kwargs:
kwargs["is_private"] = kwargs.pop("isprivate")
if "filename" in kwargs:
kwargs["file_name"] = kwargs.pop("filename")
kwargs['summary'] = description
data = f.read()
if not isinstance(data, bytes):
data = data.encode(locale.getpreferredencoding())
kwargs['data'] = Binary(data)
kwargs['ids'] = self._listify(idlist)
if 'file_name' not in kwargs and hasattr(f, "name"):
kwargs['file_name'] = os.path.basename(f.name)
if 'content_type' not in kwargs:
ctype = None
if kwargs['file_name']:
ctype = mimetypes.guess_type(
kwargs['file_name'], strict=False)[0]
kwargs['content_type'] = ctype or 'application/octet-stream'
ret = self._proxy.Bug.add_attachment(kwargs)
if "attachments" in ret:
ret = [int(k) for k in ret["attachments"].keys()]
elif "ids" in ret:
ret = ret["ids"]
if isinstance(ret, list) and len(ret) == 1:
ret = ret[0]
return ret |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pre_translation'},{'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', '15', '57', '85', '95', '123', '139']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'old'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'},{'id': '17', 'type': 'string', 'children': [], 'value': "'bug_id'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '19', 'type': 'block', 'children': ['20', '53']},{'id': '20', 'type': 'if_statement', 'children': ['21', '29', '43']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '24', 'type': 'argument_list', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '27', 'type': 'string', 'children': [], 'value': "'bug_id'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '34', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '39', 'type': 'string', 'children': [], 'value': "'bug_id'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'string', 'children': [], 'value': "','"},{'id': '43', 'type': 'else_clause', 'children': ['44']},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '49', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '52', 'type': 'string', 'children': [], 'value': "'bug_id'"},{'id': '53', 'type': 'delete_statement', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '56', 'type': 'string', 'children': [], 'value': "'bug_id'"},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'string', 'children': [], 'value': "'component'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'if_statement', 'children': ['63', '71']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '69', 'type': 'string', 'children': [], 'value': "'component'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '76', 'type': 'string', 'children': [], 'value': "'component'"},{'id': '77', 'type': 'call', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '81', 'type': 'string', 'children': [], 'value': "'component'"},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "','"},{'id': '85', 'type': 'if_statement', 'children': ['86', '93']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'and'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'not'},{'id': '88', 'type': 'string', 'children': [], 'value': "'include_fields'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'not'},{'id': '91', 'type': 'string', 'children': [], 'value': "'column_list'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'not'},{'id': '97', 'type': 'string', 'children': [], 'value': "'include_fields'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '99', 'type': 'block', 'children': ['100', '106']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '104', 'type': 'string', 'children': [], 'value': "'include_fields'"},{'id': '105', 'type': 'list', 'children': [], 'value': '[]'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'in'},{'id': '108', 'type': 'string', 'children': [], 'value': "'column_list'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '110', 'type': 'block', 'children': ['111', '119']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '115', 'type': 'string', 'children': [], 'value': "'include_fields'"},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '118', 'type': 'string', 'children': [], 'value': "'column_list'"},{'id': '119', 'type': 'delete_statement', 'children': ['120']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '122', 'type': 'string', 'children': [], 'value': "'column_list'"},{'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': 'query'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'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': '_process_include_fields'},{'id': '133', 'type': 'argument_list', 'children': ['134', '137', '138']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '136', 'type': 'string', 'children': [], 'value': '"include_fields"'},{'id': '137', 'type': 'None', 'children': []},{'id': '138', 'type': 'None', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '!='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'old'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': '"RHBugzilla pretranslated query to: %s"'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'query'} | def pre_translation(self, query):
old = query.copy()
if 'bug_id' in query:
if not isinstance(query['bug_id'], list):
query['id'] = query['bug_id'].split(',')
else:
query['id'] = query['bug_id']
del query['bug_id']
if 'component' in query:
if not isinstance(query['component'], list):
query['component'] = query['component'].split(',')
if 'include_fields' not in query and 'column_list' not in query:
return
if 'include_fields' not in query:
query['include_fields'] = []
if 'column_list' in query:
query['include_fields'] = query['column_list']
del query['column_list']
query.update(self._process_include_fields(query["include_fields"],
None, None))
if old != query:
log.debug("RHBugzilla pretranslated query to: %s", query) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_differences'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '29', '45', '63']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': '"Check that mail differences are within the limits."'},{'id': '13', 'type': 'if_statement', 'children': ['14', '21']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '20'], 'value': '<'},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'size_threshold'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"Skip checking for size differences."'},{'id': '29', 'type': 'if_statement', 'children': ['30', '37']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '36'], 'value': '<'},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'content_threshold'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'block', 'children': ['38']},{'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': 'logger'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '"Skip checking for content differences."'},{'id': '45', 'type': 'if_statement', 'children': ['46', '61']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '54'], 'value': 'and'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': '<'},{'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': 'conf'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'size_threshold'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '60'], 'value': '<'},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'content_threshold'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': []},{'id': '63', 'type': 'for_statement', 'children': ['64', '67', '74']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'combinations'},{'id': '69', 'type': 'argument_list', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '73', 'type': 'integer', 'children': [], 'value': '2'},{'id': '74', 'type': 'block', 'children': ['75', '123']},{'id': '75', 'type': 'if_statement', 'children': ['76', '84']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '82'], 'value': '>'},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'size_threshold'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'block', 'children': ['85', '98', '112']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'size_difference'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '95'], 'value': '-'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': '"{} and {} differs by {} bytes in size."'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'size_difference'},{'id': '112', 'type': 'if_statement', 'children': ['113', '120']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '>'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'size_difference'},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'size_threshold'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'SizeDiffAboveThreshold'},{'id': '123', 'type': 'if_statement', 'children': ['124', '132']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '130'], 'value': '>'},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'content_threshold'},{'id': '130', 'type': 'unary_operator', 'children': ['131'], 'value': '-'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'block', 'children': ['133', '143', '157']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'content_difference'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"{} and {} differs by {} bytes in content."'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'content_difference'},{'id': '157', 'type': 'if_statement', 'children': ['158', '165']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '>'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'content_difference'},{'id': '160', 'type': 'attribute', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'content_threshold'},{'id': '165', 'type': 'block', 'children': ['166', '186']},{'id': '166', 'type': 'if_statement', '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': 'conf'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'show_diff'},{'id': '172', 'type': 'block', 'children': ['173']},{'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': 'logger'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'info'},{'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': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'pretty_diff'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'mail_a'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mail_b'},{'id': '186', 'type': 'raise_statement', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ContentDiffAboveThreshold'} | def check_differences(self):
logger.info("Check that mail differences are within the limits.")
if self.conf.size_threshold < 0:
logger.info("Skip checking for size differences.")
if self.conf.content_threshold < 0:
logger.info("Skip checking for content differences.")
if self.conf.size_threshold < 0 and self.conf.content_threshold < 0:
return
for mail_a, mail_b in combinations(self.pool, 2):
if self.conf.size_threshold > -1:
size_difference = abs(mail_a.size - mail_b.size)
logger.debug("{} and {} differs by {} bytes in size.".format(
mail_a, mail_b, size_difference))
if size_difference > self.conf.size_threshold:
raise SizeDiffAboveThreshold
if self.conf.content_threshold > -1:
content_difference = self.diff(mail_a, mail_b)
logger.debug(
"{} and {} differs by {} bytes in content.".format(
mail_a, mail_b, content_difference))
if content_difference > self.conf.content_threshold:
if self.conf.show_diff:
logger.info(self.pretty_diff(mail_a, mail_b))
raise ContentDiffAboveThreshold |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filecache'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fail_silently'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '231', '254']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'''\n filecache is called and the decorator should be returned.\n '''"},{'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']},{'id': '14', 'type': 'function_name', 'children': [], 'value': 'filecache_decorator'},{'id': '15', 'type': 'parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '17', 'type': 'block', 'children': ['18', '161', '229']},{'id': '18', 'type': 'decorated_definition', 'children': ['19', '26']},{'id': '19', 'type': 'decorator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_functools'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '26', 'type': 'function_definition', 'children': ['27', '28', '33']},{'id': '27', 'type': 'function_name', 'children': [], 'value': 'function_with_cache'},{'id': '28', 'type': 'parameters', 'children': ['29', '31']},{'id': '29', 'type': 'list_splat_pattern', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '31', 'type': 'dictionary_splat_pattern', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '33', 'type': 'block', 'children': ['34', '102', '112', '159']},{'id': '34', 'type': 'try_statement', 'children': ['35', '81']},{'id': '35', 'type': 'block', 'children': ['36', '45']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_args_key'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '51', 'type': 'block', 'children': ['52', '60']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '60', 'type': 'if_statement', 'children': ['61', '76']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'or'},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '75'], 'value': '<'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '72'], 'value': '-'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_time'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'timesig'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '81', 'type': 'except_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '83', 'type': 'block', 'children': ['84', '92', '97']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'error_str'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_traceback'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'format_exc'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_log_error'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'error_str'},{'id': '97', 'type': 'if_statement', 'children': ['98', '100']},{'id': '98', 'type': 'not_operator', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'fail_silently'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'raise_statement', 'children': []},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '107', 'type': 'argument_list', 'children': ['108', '110']},{'id': '108', 'type': 'list_splat', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '110', 'type': 'dictionary_splat', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '112', 'type': 'try_statement', 'children': ['113', '138']},{'id': '113', 'type': 'block', 'children': ['114', '130']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '121']},{'id': '116', 'type': 'subscript', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_retval'},{'id': '123', 'type': 'argument_list', 'children': ['124', '129']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_time'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '128', 'type': 'argument_list', 'children': []},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'retval'},{'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': 'function'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sync'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'except_clause', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '140', 'type': 'block', 'children': ['141', '149', '154']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'error_str'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_traceback'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'format_exc'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_log_error'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'error_str'},{'id': '154', 'type': 'if_statement', 'children': ['155', '157']},{'id': '155', 'type': 'not_operator', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'fail_silently'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'raise_statement', 'children': []},{'id': '159', 'type': 'return_statement', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '161', 'type': 'if_statement', 'children': ['162', '168']},{'id': '162', 'type': 'not_operator', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '167', 'type': 'string', 'children': [], 'value': "'_db'"},{'id': '168', 'type': 'block', 'children': ['169', '176', '221']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_get_cache_name'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '176', 'type': 'if_statement', 'children': ['177', '180', '189']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'in'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'OPEN_DBS'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'OPEN_DBS'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191', '202', '210']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_shelve'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '207']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'OPEN_DBS'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'cache_name'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_db'},{'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': 'atexit'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'function_with_cache'},{'id': '225', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'function'},{'id': '228', 'type': 'identifier', 'children': [], 'value': '_db'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'function_with_cache'},{'id': '231', 'type': 'if_statement', 'children': ['232', '240']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '237'], 'value': '=='},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'FunctionType'},{'id': '240', 'type': 'block', 'children': ['241', '245', '249']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'seconds_of_validity'},{'id': '248', 'type': 'None', 'children': []},{'id': '249', 'type': 'return_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'filecache_decorator'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'filecache_decorator'} | def filecache(seconds_of_validity=None, fail_silently=False):
'''
filecache is called and the decorator should be returned.
'''
def filecache_decorator(function):
@_functools.wraps(function)
def function_with_cache(*args, **kwargs):
try:
key = _args_key(function, args, kwargs)
if key in function._db:
rv = function._db[key]
if seconds_of_validity is None or _time.time() - rv.timesig < seconds_of_validity:
return rv.data
except Exception:
error_str = _traceback.format_exc()
_log_error(error_str)
if not fail_silently:
raise
retval = function(*args, **kwargs)
try:
function._db[key] = _retval(_time.time(), retval)
function._db.sync()
except Exception:
error_str = _traceback.format_exc()
_log_error(error_str)
if not fail_silently:
raise
return retval
if not hasattr(function, '_db'):
cache_name = _get_cache_name(function)
if cache_name in OPEN_DBS:
function._db = OPEN_DBS[cache_name]
else:
function._db = _shelve.open(cache_name)
OPEN_DBS[cache_name] = function._db
atexit.register(function._db.close)
function_with_cache._db = function._db
return function_with_cache
if type(seconds_of_validity) == types.FunctionType:
func = seconds_of_validity
seconds_of_validity = None
return filecache_decorator(func)
return filecache_decorator |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '17', '255']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'await', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'disconnect'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '28', '74']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'},{'id': '20', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '<'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'integer', 'children': [], 'value': '2'},{'id': '28', 'type': 'block', 'children': ['29', '62']},{'id': '29', 'type': 'if_statement', 'children': ['30', '35', '41', '50']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '32'], 'value': 'and'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'},{'id': '33', 'type': 'string', 'children': [], 'value': "'model_name'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'connect() got multiple values for model_name'"},{'id': '41', 'type': 'elif_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'model_name'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'model_name'"},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'await', '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': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_connector'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'connect_model'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '72', 'type': 'dictionary_splat', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76', '88', '100', '117', '136', '156', '168', '181', '198', '216', '244']},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'string', 'children': [], 'value': "'model_name'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'raise_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'concatenated_string', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'connect() got values for both '"},{'id': '87', 'type': 'string', 'children': [], 'value': "'model_name and endpoint'"},{'id': '88', 'type': 'if_statement', 'children': ['89', '94']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '91'], 'value': 'and'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'},{'id': '92', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'raise_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'connect() got multiple values for endpoint'"},{'id': '100', 'type': 'if_statement', 'children': ['101', '111']},{'id': '101', 'type': 'boolean_operator', 'children': ['102', '108'], 'value': 'and'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '107'], 'value': '<'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '107', 'type': 'integer', 'children': [], 'value': '2'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'not'},{'id': '109', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'raise_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'connect() missing value for uuid'"},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'has_userpass'},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'boolean_operator', 'children': ['122', '128'], 'value': 'or'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '127'], 'value': '>='},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '127', 'type': 'integer', 'children': [], 'value': '4'},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'set', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '132', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'has_macaroons'},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'boolean_operator', 'children': ['141', '147'], 'value': 'or'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '146'], 'value': '>='},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '146', 'type': 'integer', 'children': [], 'value': '6'},{'id': '147', 'type': 'not_operator', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'set', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '152', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'isdisjoint'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '156', 'type': 'if_statement', 'children': ['157', '162']},{'id': '157', 'type': 'not_operator', 'children': ['158']},{'id': '158', 'type': '()', 'children': ['159']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '161'], 'value': 'or'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'has_userpass'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'has_macaroons'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'raise_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'connect() missing auth params'"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'arg_names'},{'id': '171', 'type': 'list', 'children': ['172', '173', '174', '175', '176', '177', '178', '179', '180'], 'value': "[\n 'endpoint',\n 'uuid',\n 'username',\n 'password',\n 'cacert',\n 'bakery_client',\n 'macaroons',\n 'loop',\n 'max_frame_size',\n ]"},{'id': '172', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '173', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '175', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '176', 'type': 'string', 'children': [], 'value': "'cacert'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '179', 'type': 'string', 'children': [], 'value': "'loop'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'max_frame_size'"},{'id': '181', 'type': 'for_statement', 'children': ['182', '185', '189']},{'id': '182', 'type': 'pattern_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '197']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'arg_names'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '198', 'type': 'if_statement', 'children': ['199', '208']},{'id': '199', 'type': 'not_operator', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'set', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '204', 'type': 'string', 'children': [], 'value': "'uuid'"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'raise_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'concatenated_string', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'endpoint and uuid are required '"},{'id': '215', 'type': 'string', 'children': [], 'value': "'if model_name not given'"},{'id': '216', 'type': 'if_statement', 'children': ['217', '236']},{'id': '217', 'type': 'not_operator', 'children': ['218']},{'id': '218', 'type': '()', 'children': ['219']},{'id': '219', 'type': 'boolean_operator', 'children': ['220', '228'], 'value': 'or'},{'id': '220', 'type': 'call', 'children': ['221', '226']},{'id': '221', 'type': 'attribute', 'children': ['222', '225']},{'id': '222', 'type': 'set', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '224', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '228', 'type': 'call', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'set', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '232', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'raise_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'concatenated_string', 'children': ['242', '243']},{'id': '242', 'type': 'string', 'children': [], 'value': "'Authentication parameters are required '"},{'id': '243', 'type': 'string', 'children': [], 'value': "'if model_name not given'"},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'await', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': '_connector'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'dictionary_splat', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'await', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '260', 'type': 'identifier', 'children': [], 'value': '_after_connect'},{'id': '261', 'type': 'argument_list', 'children': []} | async def connect(self, *args, **kwargs):
await self.disconnect()
if 'endpoint' not in kwargs and len(args) < 2:
if args and 'model_name' in kwargs:
raise TypeError('connect() got multiple values for model_name')
elif args:
model_name = args[0]
else:
model_name = kwargs.pop('model_name', None)
await self._connector.connect_model(model_name, **kwargs)
else:
if 'model_name' in kwargs:
raise TypeError('connect() got values for both '
'model_name and endpoint')
if args and 'endpoint' in kwargs:
raise TypeError('connect() got multiple values for endpoint')
if len(args) < 2 and 'uuid' not in kwargs:
raise TypeError('connect() missing value for uuid')
has_userpass = (len(args) >= 4 or
{'username', 'password'}.issubset(kwargs))
has_macaroons = (len(args) >= 6 or not
{'bakery_client', 'macaroons'}.isdisjoint(kwargs))
if not (has_userpass or has_macaroons):
raise TypeError('connect() missing auth params')
arg_names = [
'endpoint',
'uuid',
'username',
'password',
'cacert',
'bakery_client',
'macaroons',
'loop',
'max_frame_size',
]
for i, arg in enumerate(args):
kwargs[arg_names[i]] = arg
if not {'endpoint', 'uuid'}.issubset(kwargs):
raise ValueError('endpoint and uuid are required '
'if model_name not given')
if not ({'username', 'password'}.issubset(kwargs) or
{'bakery_client', 'macaroons'}.intersection(kwargs)):
raise ValueError('Authentication parameters are required '
'if model_name not given')
await self._connector.connect(**kwargs)
await self._after_connect() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_watch'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '283', '290', '298', '306', '314']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '9']},{'id': '7', 'type': 'function_name', 'children': [], 'value': '_all_watcher'},{'id': '8', 'type': 'parameters', 'children': []},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'try_statement', 'children': ['11', '258', '262', '273']},{'id': '11', 'type': 'block', 'children': ['12', '27']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'allwatcher'},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'AllWatcherFacade'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'from_connection'},{'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': 'connection'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'while_statement', 'children': ['28', '36']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_watch_stopping'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '169', '194', '250']},{'id': '37', 'type': 'try_statement', 'children': ['38', '63', '100']},{'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': 'results'},{'id': '42', 'type': 'await', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'run_with_interrupt'},{'id': '47', 'type': 'argument_list', 'children': ['48', '53', '56']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'allwatcher'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'Next'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_watch_stopping'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_connector'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '63', 'type': 'except_clause', 'children': ['64', '68']},{'id': '64', 'type': 'as_pattern', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'JujuAPIError'},{'id': '66', 'type': 'as_pattern_target', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '68', 'type': 'block', 'children': ['69', '78', '88', '95', '99']},{'id': '69', 'type': 'if_statement', 'children': ['70', '76']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'string', 'children': [], 'value': "'watcher was stopped'"},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'raise_statement', 'children': []},{'id': '78', 'type': 'if_statement', 'children': ['79', '86']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_watch_stopping'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'break_statement', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': "'Watcher: watcher stopped, restarting'"},{'id': '95', 'type': 'delete_statement', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'allwatcher'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Id'},{'id': '99', 'type': 'continue_statement', 'children': []},{'id': '100', 'type': 'except_clause', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'websockets'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ConnectionClosed'},{'id': '104', 'type': 'block', 'children': ['105', '115']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '108', 'type': 'attribute', 'children': ['109', '114']},{'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': 'connection'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '115', 'type': 'if_statement', 'children': ['116', '123', '166']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': '=='},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ERROR'},{'id': '123', 'type': 'block', 'children': ['124', '131', '142', '161', '165']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'Watcher: connection closed, reopening'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'await', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '141']},{'id': '134', 'type': 'attribute', 'children': ['135', '140']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'reconnect'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '150']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '!='},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'monitor'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'CONNECTED'},{'id': '150', 'type': 'block', 'children': ['151', '160']},{'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': 'log'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'concatenated_string', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'Watcher: automatic reconnect '"},{'id': '159', 'type': 'string', 'children': [], 'value': "'failed; stopping watcher'"},{'id': '160', 'type': 'break_statement', 'children': []},{'id': '161', 'type': 'delete_statement', 'children': ['162']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'allwatcher'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'Id'},{'id': '165', 'type': 'continue_statement', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'break_statement', 'children': []},{'id': '169', 'type': 'if_statement', 'children': ['170', '177']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_watch_stopping'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'block', 'children': ['178', '193']},{'id': '178', 'type': 'try_statement', 'children': ['179', '187']},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'await', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'allwatcher'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Stop'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'except_clause', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'websockets'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ConnectionClosed'},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'pass_statement', 'children': []},{'id': '193', 'type': 'break_statement', 'children': []},{'id': '194', 'type': 'for_statement', 'children': ['195', '196', '199']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'deltas'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'try_statement', 'children': ['201', '232']},{'id': '201', 'type': 'block', 'children': ['202', '209', '222']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'get_entity_delta'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '214']},{'id': '211', 'type': 'pattern_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'old_obj'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_obj'},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'apply_delta'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'await', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_notify_observers'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'old_obj'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'new_obj'},{'id': '232', 'type': 'except_clause', 'children': ['233', '237']},{'id': '233', 'type': 'as_pattern', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '235', 'type': 'as_pattern_target', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245']},{'id': '244', 'type': 'string', 'children': [], 'value': '"unknown delta type: %s"'},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '249', 'type': 'integer', 'children': [], 'value': '0'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', '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': '_watch_received'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '257', 'type': 'argument_list', 'children': []},{'id': '258', 'type': 'except_clause', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'CancelledError'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'pass_statement', 'children': []},{'id': '262', 'type': 'except_clause', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '264', 'type': 'block', 'children': ['265', '272']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'Error in watcher'"},{'id': '272', 'type': 'raise_statement', 'children': []},{'id': '273', 'type': 'finally_clause', 'children': ['274']},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '282']},{'id': '277', 'type': 'attribute', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': '_watch_stopped'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '282', 'type': 'argument_list', 'children': []},{'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': 'log'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'string', 'children': [], 'value': "'Starting watcher task'"},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '297']},{'id': '292', 'type': 'attribute', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_watch_received'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '297', 'type': 'argument_list', 'children': []},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'call', 'children': ['300', '305']},{'id': '300', 'type': 'attribute', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '303', 'type': 'identifier', 'children': [], 'value': '_watch_stopping'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '313']},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '311', 'type': 'identifier', 'children': [], 'value': '_watch_stopped'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '323']},{'id': '316', 'type': 'attribute', 'children': ['317', '322']},{'id': '317', 'type': 'attribute', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '320', 'type': 'identifier', 'children': [], 'value': '_connector'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'create_task'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': '_all_watcher'},{'id': '326', 'type': 'argument_list', 'children': []} | def _watch(self):
async def _all_watcher():
try:
allwatcher = client.AllWatcherFacade.from_connection(
self.connection())
while not self._watch_stopping.is_set():
try:
results = await utils.run_with_interrupt(
allwatcher.Next(),
self._watch_stopping,
loop=self._connector.loop)
except JujuAPIError as e:
if 'watcher was stopped' not in str(e):
raise
if self._watch_stopping.is_set():
break
log.warning(
'Watcher: watcher stopped, restarting')
del allwatcher.Id
continue
except websockets.ConnectionClosed:
monitor = self.connection().monitor
if monitor.status == monitor.ERROR:
log.warning(
'Watcher: connection closed, reopening')
await self.connection().reconnect()
if monitor.status != monitor.CONNECTED:
log.error('Watcher: automatic reconnect '
'failed; stopping watcher')
break
del allwatcher.Id
continue
else:
break
if self._watch_stopping.is_set():
try:
await allwatcher.Stop()
except websockets.ConnectionClosed:
pass
break
for delta in results.deltas:
try:
delta = get_entity_delta(delta)
old_obj, new_obj = self.state.apply_delta(delta)
await self._notify_observers(delta, old_obj, new_obj)
except KeyError as e:
log.debug("unknown delta type: %s", e.args[0])
self._watch_received.set()
except CancelledError:
pass
except Exception:
log.exception('Error in watcher')
raise
finally:
self._watch_stopped.set()
log.debug('Starting watcher task')
self._watch_received.clear()
self._watch_stopping.clear()
self._watch_stopped.clear()
self._connector.loop.create_task(_all_watcher()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_machine'},{'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': 'spec'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'disks'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '26', '105', '112', '128', '148', '157', '172', '183', '193', '205', '215', '242', '250']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'AddMachineParams'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'if_statement', 'children': ['30', '36', '85']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': '"ssh:"'},{'id': '36', 'type': 'block', 'children': ['37', '49', '60', '77']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '43']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'placement'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'private_key_path'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '":"'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sshProvisioner'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'provisioner'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'SSHProvisioner'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'private_key_path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'private_key_path'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sshProvisioner'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'provision_machine'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87', '94']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'placement'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'parse_placement'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '94', 'type': 'if_statement', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'placement'},{'id': '96', 'type': 'block', 'children': ['97']},{'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': 'params'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'placement'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'placement'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'jobs'},{'id': '110', 'type': 'list', 'children': ['111'], 'value': "['JobHostUnits']"},{'id': '111', 'type': 'string', 'children': [], 'value': "'JobHostUnits'"},{'id': '112', 'type': 'if_statement', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'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': 'client'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Value'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'from_json'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'constraints'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'disks'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'disks'},{'id': '136', 'type': 'list_comprehension', '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': 'client'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'Constraints'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'from_json'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'disks'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'client_facade'},{'id': '160', 'type': 'call', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ClientFacade'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'from_connection'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '175', 'type': 'await', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'client_facade'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'AddMachines'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'list', 'children': ['182'], 'value': '[params]'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '186', 'type': 'attribute', 'children': ['187', '192']},{'id': '187', 'type': 'subscript', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'machines'},{'id': '191', 'type': 'integer', 'children': [], 'value': '0'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'raise_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'},{'id': '201', 'type': 'string', 'children': [], 'value': '"Error adding machine: %s"'},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'machine_id'},{'id': '208', 'type': 'attribute', 'children': ['209', '214']},{'id': '209', 'type': 'subscript', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'machines'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'machine'},{'id': '215', 'type': 'if_statement', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'if_statement', 'children': ['219', '225']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'string', 'children': [], 'value': '"ssh:"'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'await', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'sshProvisioner'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'install_agent'},{'id': '232', 'type': 'argument_list', 'children': ['233', '238', '241']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'nonce'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'machine_id'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': "'Added new machine %s'"},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'machine_id'},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'await', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': '_wait_for_new'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'machine'"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'machine_id'} | async def add_machine(
self, spec=None, constraints=None, disks=None, series=None):
params = client.AddMachineParams()
if spec:
if spec.startswith("ssh:"):
placement, target, private_key_path = spec.split(":")
user, host = target.split("@")
sshProvisioner = provisioner.SSHProvisioner(
host=host,
user=user,
private_key_path=private_key_path,
)
params = sshProvisioner.provision_machine()
else:
placement = parse_placement(spec)
if placement:
params.placement = placement[0]
params.jobs = ['JobHostUnits']
if constraints:
params.constraints = client.Value.from_json(constraints)
if disks:
params.disks = [
client.Constraints.from_json(o) for o in disks]
if series:
params.series = series
client_facade = client.ClientFacade.from_connection(self.connection())
results = await client_facade.AddMachines([params])
error = results.machines[0].error
if error:
raise ValueError("Error adding machine: %s" % error.message)
machine_id = results.machines[0].machine
if spec:
if spec.startswith("ssh:"):
await sshProvisioner.install_agent(
self.connection(),
params.nonce,
machine_id,
)
log.debug('Added new machine %s', machine_id)
return await self._wait_for_new('machine', machine_id) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_action_output'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'action_uuid'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '25', '38', '79', '92', '102', '129']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'action_facade'},{'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': 'client'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ActionFacade'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'from_connection'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'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': 'connection'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '28', 'type': 'list', 'children': ['29'], 'value': "[{'tag': tag.action(action_uuid)}]"},{'id': '29', 'type': 'dictionary', 'children': ['30']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'tag'"},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'action_uuid'},{'id': '38', 'type': 'function_definition', 'children': ['39', '40', '41']},{'id': '39', 'type': 'function_name', 'children': [], 'value': '_wait_for_action_status'},{'id': '40', 'type': 'parameters', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'while_statement', 'children': ['43', '44']},{'id': '43', 'type': 'True', 'children': []},{'id': '44', 'type': 'block', 'children': ['45', '55']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'action_output'},{'id': '48', 'type': 'await', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'action_facade'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'Actions'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '55', 'type': 'if_statement', 'children': ['56', '67', '69']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '64'], 'value': 'in'},{'id': '57', 'type': 'attribute', 'children': ['58', '63']},{'id': '58', 'type': 'subscript', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'action_output'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '64', 'type': 'tuple', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'completed'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'failed'"},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': []},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'await', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'await', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'wait_for'},{'id': '85', 'type': 'argument_list', 'children': ['86', '89']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_wait_for_action_status'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'action_output'},{'id': '95', 'type': 'await', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'action_facade'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'Actions'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '102', 'type': 'if_statement', 'children': ['103', '112', '117']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '111'], 'value': 'is'},{'id': '104', 'type': 'attribute', 'children': ['105', '110']},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'action_output'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '111', 'type': 'None', 'children': []},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '116', 'type': 'dictionary', 'children': []},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '122', 'type': 'attribute', 'children': ['123', '128']},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'action_output'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'output'} | async def get_action_output(self, action_uuid, wait=None):
action_facade = client.ActionFacade.from_connection(
self.connection()
)
entity = [{'tag': tag.action(action_uuid)}]
async def _wait_for_action_status():
while True:
action_output = await action_facade.Actions(entity)
if action_output.results[0].status in ('completed', 'failed'):
return
else:
await asyncio.sleep(1)
await asyncio.wait_for(
_wait_for_action_status(),
timeout=wait)
action_output = await action_facade.Actions(entity)
if action_output.results[0].output is None:
output = {}
else:
output = action_output.results[0].output
return output |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'connect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '17']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'await', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'disconnect'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '28', '76']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'},{'id': '20', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '<'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'integer', 'children': [], 'value': '2'},{'id': '28', 'type': 'block', 'children': ['29', '64']},{'id': '29', 'type': 'if_statement', 'children': ['30', '35', '43', '52']},{'id': '30', 'type': 'boolean_operator', 'children': ['31', '32'], 'value': 'and'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'},{'id': '33', 'type': 'string', 'children': [], 'value': "'model_name'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'concatenated_string', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'connect() got multiple values for '"},{'id': '42', 'type': 'string', 'children': [], 'value': "'controller_name'"},{'id': '43', 'type': 'elif_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'controller_name'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'else_clause', 'children': ['53']},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'controller_name'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'controller_name'"},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'await', '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': '_connector'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'connect_controller'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'controller_name'},{'id': '74', 'type': 'dictionary_splat', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78', '90', '102', '121', '141', '153', '165', '182', '194', '222']},{'id': '78', 'type': 'if_statement', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'},{'id': '80', 'type': 'string', 'children': [], 'value': "'controller_name'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'TypeError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'concatenated_string', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'connect() got values for both '"},{'id': '89', 'type': 'string', 'children': [], 'value': "'controller_name and endpoint'"},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '93'], 'value': 'and'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'},{'id': '94', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'raise_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "'connect() got multiple values for endpoint'"},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'has_userpass'},{'id': '105', 'type': '()', 'children': ['106']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '113'], 'value': 'or'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '112'], 'value': '>='},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '112', 'type': 'integer', 'children': [], 'value': '3'},{'id': '113', 'type': 'call', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'set', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '117', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'has_macaroons'},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '132'], 'value': 'or'},{'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': 'args'},{'id': '131', 'type': 'integer', 'children': [], 'value': '5'},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '139']},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'set', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isdisjoint'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '141', 'type': 'if_statement', 'children': ['142', '147']},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': '()', 'children': ['144']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '146'], 'value': 'or'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'has_userpass'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'has_macaroons'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'string', 'children': [], 'value': "'connect() missing auth params'"},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'arg_names'},{'id': '156', 'type': 'list', 'children': ['157', '158', '159', '160', '161', '162', '163', '164'], 'value': "[\n 'endpoint',\n 'username',\n 'password',\n 'cacert',\n 'bakery_client',\n 'macaroons',\n 'loop',\n 'max_frame_size',\n ]"},{'id': '157', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '158', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '159', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '160', 'type': 'string', 'children': [], 'value': "'cacert'"},{'id': '161', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '162', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '163', 'type': 'string', 'children': [], 'value': "'loop'"},{'id': '164', 'type': 'string', 'children': [], 'value': "'max_frame_size'"},{'id': '165', 'type': 'for_statement', 'children': ['166', '169', '173']},{'id': '166', 'type': 'pattern_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '181']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'arg_names'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '182', 'type': 'if_statement', 'children': ['183', '186']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'not'},{'id': '184', 'type': 'string', 'children': [], 'value': "'endpoint'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'raise_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'concatenated_string', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "'endpoint is required '"},{'id': '193', 'type': 'string', 'children': [], 'value': "'if controller_name not given'"},{'id': '194', 'type': 'if_statement', 'children': ['195', '214']},{'id': '195', 'type': 'not_operator', 'children': ['196']},{'id': '196', 'type': '()', 'children': ['197']},{'id': '197', 'type': 'boolean_operator', 'children': ['198', '206'], 'value': 'or'},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'set', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '202', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '206', 'type': 'call', 'children': ['207', '212']},{'id': '207', 'type': 'attribute', 'children': ['208', '211']},{'id': '208', 'type': 'set', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': "'bakery_client'"},{'id': '210', 'type': 'string', 'children': [], 'value': "'macaroons'"},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'raise_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'concatenated_string', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "'Authentication parameters are required '"},{'id': '221', 'type': 'string', 'children': [], 'value': "'if controller_name not given'"},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'await', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '230']},{'id': '225', 'type': 'attribute', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': '_connector'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'dictionary_splat', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | async def connect(self, *args, **kwargs):
await self.disconnect()
if 'endpoint' not in kwargs and len(args) < 2:
if args and 'model_name' in kwargs:
raise TypeError('connect() got multiple values for '
'controller_name')
elif args:
controller_name = args[0]
else:
controller_name = kwargs.pop('controller_name', None)
await self._connector.connect_controller(controller_name, **kwargs)
else:
if 'controller_name' in kwargs:
raise TypeError('connect() got values for both '
'controller_name and endpoint')
if args and 'endpoint' in kwargs:
raise TypeError('connect() got multiple values for endpoint')
has_userpass = (len(args) >= 3 or
{'username', 'password'}.issubset(kwargs))
has_macaroons = (len(args) >= 5 or not
{'bakery_client', 'macaroons'}.isdisjoint(kwargs))
if not (has_userpass or has_macaroons):
raise TypeError('connect() missing auth params')
arg_names = [
'endpoint',
'username',
'password',
'cacert',
'bakery_client',
'macaroons',
'loop',
'max_frame_size',
]
for i, arg in enumerate(args):
kwargs[arg_names[i]] = arg
if 'endpoint' not in kwargs:
raise ValueError('endpoint is required '
'if controller_name not given')
if not ({'username', 'password'}.issubset(kwargs) or
{'bakery_client', 'macaroons'}.intersection(kwargs)):
raise ValueError('Authentication parameters are required '
'if controller_name not given')
await self._connector.connect(**kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_credential'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '34', '52', '65', '102', '182', '190', '205', '233', '263']},{'id': '21', 'type': 'if_statement', 'children': ['22', '24']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '28', 'type': 'await', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_cloud'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'if_statement', 'children': ['35', '37']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'owner'},{'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': 'owner'},{'id': '41', 'type': 'subscript', 'children': ['42', '51']},{'id': '42', 'type': 'subscript', 'children': ['43', '50']},{'id': '43', 'type': 'attribute', 'children': ['44', '49']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '50', 'type': 'string', 'children': [], 'value': "'user-info'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'identity'"},{'id': '52', 'type': 'if_statement', 'children': ['53', '57']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '55'], 'value': 'and'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '55', 'type': 'not_operator', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'JujuError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'Name must be provided for credential'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '68']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '68', 'type': 'block', 'children': ['69', '85']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'credential'},{'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': '_connector'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'jujudata'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'load_credential'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'JujuError'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'Unable to find credential: {}'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '102', 'type': 'if_statement', 'children': ['103', '114']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '109'], 'value': 'and'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'auth_type'},{'id': '108', 'type': 'string', 'children': [], 'value': "'jsonfile'"},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'},{'id': '110', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'try_statement', 'children': ['116', '128']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '127', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '128', 'type': 'except_clause', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'JSONDecodeError'},{'id': '132', 'type': 'block', 'children': ['133', '144']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'cred_path'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '143', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '144', 'type': 'if_statement', 'children': ['145', '150']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'cred_path'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'block', 'children': ['151', '159', '170']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cred_json'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'CloudCredential'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'from_json'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cred_json'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '177']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '176', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'cred_path'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'read_text'},{'id': '181', 'type': 'argument_list', 'children': []},{'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': 'log'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': "'Uploading credential %s'"},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'cloud_facade'},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'CloudFacade'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'from_connection'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'tagged_credentials'},{'id': '208', 'type': 'list', 'children': ['209'], 'value': "[\n client.UpdateCloudCredential(\n tag=tag.credential(cloud, tag.untag('user-', owner), name),\n credential=credential,\n )]"},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'UpdateCloudCredential'},{'id': '213', 'type': 'argument_list', 'children': ['214', '230']},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222', '229']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'untag'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': "'user-'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'credential'},{'id': '233', 'type': 'if_statement', 'children': ['234', '239', '253']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '238'], 'value': '>='},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'cloud_facade'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '238', 'type': 'integer', 'children': [], 'value': '3'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'await', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'cloud_facade'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'UpdateCredentialsCheckModels'},{'id': '246', 'type': 'argument_list', 'children': ['247', '250']},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'credentials'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'tagged_credentials'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'await', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'cloud_facade'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'UpdateCredentials'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'tagged_credentials'},{'id': '263', 'type': 'return_statement', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'name'} | async def add_credential(self, name=None, credential=None, cloud=None,
owner=None, force=False):
if not cloud:
cloud = await self.get_cloud()
if not owner:
owner = self.connection().info['user-info']['identity']
if credential and not name:
raise errors.JujuError('Name must be provided for credential')
if not credential:
name, credential = self._connector.jujudata.load_credential(cloud,
name)
if credential is None:
raise errors.JujuError(
'Unable to find credential: {}'.format(name))
if credential.auth_type == 'jsonfile' and 'file' in credential.attrs:
try:
json.loads(credential.attrs['file'])
except json.JSONDecodeError:
cred_path = Path(credential.attrs['file'])
if cred_path.exists():
cred_json = credential.to_json()
credential = client.CloudCredential.from_json(cred_json)
credential.attrs['file'] = cred_path.read_text()
log.debug('Uploading credential %s', name)
cloud_facade = client.CloudFacade.from_connection(self.connection())
tagged_credentials = [
client.UpdateCloudCredential(
tag=tag.credential(cloud, tag.untag('user-', owner), name),
credential=credential,
)]
if cloud_facade.version >= 3:
await cloud_facade.UpdateCredentialsCheckModels(
credentials=tagged_credentials, force=force,
)
else:
await cloud_facade.UpdateCredentials(tagged_credentials)
return name |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'matches'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'specs'},{'id': '7', 'type': 'block', 'children': ['8', '67']},{'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'specs'},{'id': '11', 'type': 'block', 'children': ['12', '38']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16', '28']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'},{'id': '14', 'type': 'string', 'children': [], 'value': "':'"},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'endpoint_name'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "':'"},{'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', '35']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'endpoint_name'},{'id': '35', 'type': 'expression_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '43', '63']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '61']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '53', '54'], 'value': 'and'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '=='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'app_name'},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'application'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '53', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'endpoint_name'},{'id': '56', 'type': 'tuple', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'break_statement', 'children': []},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'True', 'children': []} | def matches(self, *specs):
for spec in specs:
if ':' in spec:
app_name, endpoint_name = spec.split(':')
else:
app_name, endpoint_name = spec, None
for endpoint in self.endpoints:
if app_name == endpoint.application.name and \
endpoint_name in (endpoint.name, None):
break
else:
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'requirement_files'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'keep_wheels'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'archive_destination_dir'},{'id': '16', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'python_versions'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'validate_archive'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'wheel_args'},{'id': '25', 'type': 'string', 'children': [], 'value': "''"},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'archive_format'},{'id': '28', 'type': 'string', 'children': [], 'value': "'zip'"},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'build_tag'},{'id': '31', 'type': 'string', 'children': [], 'value': "''"},{'id': '32', 'type': 'block', 'children': ['33', '40', '48', '55', '89', '98', '106', '118', '130', '159', '166', '179', '186', '204', '215', '227', '233', '246', '253', '274', '282', '290']},{'id': '33', 'type': 'if_statement', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'validate_archive'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_assert_virtualenv_is_installed'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'Creating archive for %s...'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_source'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '55', 'type': 'if_statement', 'children': ['56', '83']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '65'], 'value': 'and'},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '65', 'type': 'not_operator', 'children': ['66', '67']},{'id': '66', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '82', 'type': 'string', 'children': [], 'value': "'setup.py'"},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'raise_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'WagonError'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': "'Source directory must contain a setup.py file'"},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '94']},{'id': '91', 'type': 'pattern_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_source_name_and_version'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'workdir'},{'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': 'os'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'wheels_path'},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'workdir'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_WHEELS_PATH'},{'id': '130', 'type': 'try_statement', 'children': ['131', '142']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'wheels'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'wheel'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '141']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'requirement_files'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'wheels_path'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'wheel_args'},{'id': '142', 'type': 'finally_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '!='},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'processed_source'},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'},{'id': '158', 'type': 'True', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_get_platform_for_set_of_wheels'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'wheels_path'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'is_verbose'},{'id': '169', 'type': 'argument_list', 'children': []},{'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': 'logger'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': "'Platform is: %s'"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'python_versions'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_set_python_versions'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'python_versions'},{'id': '186', 'type': 'if_statement', 'children': ['187', '196']},{'id': '187', 'type': 'not_operator', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '194']},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'archive_destination_dir'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'archive_destination_dir'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'archive_name'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_set_archive_name'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212', '213', '214']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'python_versions'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'build_tag'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '218', 'type': 'call', 'children': ['219', '224']},{'id': '219', 'type': 'attribute', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'archive_destination_dir'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'archive_name'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_handle_output_file'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': '_generate_metadata_file'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238', '239', '240', '241', '242', '243', '244', '245']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'workdir'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'archive_name'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'python_versions'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'package_version'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'build_tag'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'wheels'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': '_create_wagon_archive'},{'id': '249', 'type': 'argument_list', 'children': ['250', '251', '252']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'workdir'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'archive_format'},{'id': '253', 'type': 'if_statement', 'children': ['254', '256']},{'id': '254', 'type': 'not_operator', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'keep_wheels'},{'id': '256', 'type': 'block', 'children': ['257', '264']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': "'Removing work directory...'"},{'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': 'shutil'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'rmtree'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'},{'id': '273', 'type': 'True', 'children': []},{'id': '274', 'type': 'if_statement', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'validate_archive'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'string', 'children': [], 'value': "'Wagon created successfully at: %s'"},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '290', 'type': 'return_statement', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'archive_path'} | def create(source,
requirement_files=None,
force=False,
keep_wheels=False,
archive_destination_dir='.',
python_versions=None,
validate_archive=False,
wheel_args='',
archive_format='zip',
build_tag=''):
if validate_archive:
_assert_virtualenv_is_installed()
logger.info('Creating archive for %s...', source)
processed_source = get_source(source)
if os.path.isdir(processed_source) and not \
os.path.isfile(os.path.join(processed_source, 'setup.py')):
raise WagonError(
'Source directory must contain a setup.py file')
package_name, package_version = get_source_name_and_version(
processed_source)
tempdir = tempfile.mkdtemp()
workdir = os.path.join(tempdir, package_name)
wheels_path = os.path.join(workdir, DEFAULT_WHEELS_PATH)
try:
wheels = wheel(
processed_source,
requirement_files,
wheels_path,
wheel_args)
finally:
if processed_source != source:
shutil.rmtree(processed_source, ignore_errors=True)
platform = _get_platform_for_set_of_wheels(wheels_path)
if is_verbose():
logger.debug('Platform is: %s', platform)
python_versions = _set_python_versions(python_versions)
if not os.path.isdir(archive_destination_dir):
os.makedirs(archive_destination_dir)
archive_name = _set_archive_name(
package_name, package_version, python_versions, platform, build_tag)
archive_path = os.path.join(archive_destination_dir, archive_name)
_handle_output_file(archive_path, force)
_generate_metadata_file(
workdir,
archive_name,
platform,
python_versions,
package_name,
package_version,
build_tag,
source,
wheels)
_create_wagon_archive(workdir, archive_path, archive_format)
if not keep_wheels:
logger.debug('Removing work directory...')
shutil.rmtree(tempdir, ignore_errors=True)
if validate_archive:
validate(archive_path)
logger.info('Wagon created successfully at: %s', archive_path)
return archive_path |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_trading_timeline'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '6', 'type': 'block', 'children': ['7', '9', '26', '41', '324']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "''' Build the daily-based index we will trade on '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18', '21']},{'id': '17', 'type': 'string', 'children': [], 'value': "'2000/01/01'"},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'periods'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'utc'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'utc'},{'id': '41', 'type': 'if_statement', 'children': ['42', '44', '133']},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'if_statement', 'children': ['46', '48', '70']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '48', 'type': 'block', 'children': ['49', '53']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'23h59'"},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'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': 'end'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '110']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '<'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '83', 'type': 'block', 'children': ['84', '106']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '91', 'type': 'argument_list', 'children': ['92', '103']},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '-'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '*'},{'id': '97', 'type': 'integer', 'children': [], 'value': '360'},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'datetools'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '110', 'type': 'elif_clause', 'children': ['111', '114']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '>'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'now'},{'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': 'bt_dates'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135', '142']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146', '267']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': '<'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '150', '196']},{'id': '148', 'type': 'not_operator', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '150', 'type': 'block', 'children': ['151', '163', '178', '182']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '+'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '*'},{'id': '157', 'type': 'integer', 'children': [], 'value': '360'},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'datetools'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '163', 'type': 'if_statement', 'children': ['164', '167']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'datetools'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '189', 'type': 'argument_list', 'children': ['190', '193']},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '205']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '205', 'type': 'if_statement', 'children': ['206', '209', '228']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '<'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '209', 'type': 'block', 'children': ['210', '214']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '221', 'type': 'argument_list', 'children': ['222', '225']},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '228', 'type': 'elif_clause', 'children': ['229', '232']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '>'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '232', 'type': 'block', 'children': ['233', '253']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '240', 'type': 'argument_list', 'children': ['241', '244']},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '-'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '248', 'type': 'attribute', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'datetools'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '260', 'type': 'argument_list', 'children': ['261', '264']},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '267', 'type': 'elif_clause', 'children': ['268', '271']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': '>'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'if_statement', 'children': ['273', '275', '297']},{'id': '273', 'type': 'not_operator', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '275', 'type': 'block', 'children': ['276', '280']},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'assignment', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '287', 'type': 'argument_list', 'children': ['288', '291']},{'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'string', 'children': [], 'value': "'23h59'"},{'id': '297', 'type': 'else_clause', 'children': ['298']},{'id': '298', 'type': 'block', 'children': ['299', '306', '310']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'normalize_date_format'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'EMPTY_DATES'},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'live_dates'},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '317', 'type': 'argument_list', 'children': ['318', '321']},{'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '324', 'type': 'return_statement', 'children': ['325']},{'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '+'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'bt_dates'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'live_dates'} | def build_trading_timeline(start, end):
''' Build the daily-based index we will trade on '''
EMPTY_DATES = pd.date_range('2000/01/01', periods=0, tz=pytz.utc)
now = dt.datetime.now(tz=pytz.utc)
if not start:
if not end:
bt_dates = EMPTY_DATES
live_dates = pd.date_range(
start=now,
end=normalize_date_format('23h59'))
else:
end = normalize_date_format(end)
if end < now:
bt_dates = pd.date_range(
start=end - 360 * pd.datetools.day,
end=end)
live_dates = EMPTY_DATES
elif end > now:
bt_dates = EMPTY_DATES
live_dates = pd.date_range(start=now, end=end)
else:
start = normalize_date_format(start)
if start < now:
if not end:
end = start + 360 * pd.datetools.day
if end > now:
end = now - pd.datetools.day
live_dates = EMPTY_DATES
bt_dates = pd.date_range(
start=start, end=end)
else:
end = normalize_date_format(end)
if end < now:
live_dates = EMPTY_DATES
bt_dates = pd.date_range(start=start, end=end)
elif end > now:
bt_dates = pd.date_range(
start=start, end=now - pd.datetools.day)
live_dates = pd.date_range(start=now, end=end)
elif start > now:
if not end:
bt_dates = EMPTY_DATES
live_dates = pd.date_range(
start=start,
end=normalize_date_format('23h59'))
else:
end = normalize_date_format(end)
bt_dates = EMPTY_DATES
live_dates = pd.date_range(start=start, end=end)
return bt_dates + live_dates |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gcal2jd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '7', 'type': 'block', 'children': ['8', '15', '22', '29', '41', '58', '77', '91', '103', '109', '113']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ipart'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '40'], 'value': '/'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '-'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '39', 'type': 'integer', 'children': [], 'value': '14'},{'id': '40', 'type': 'float', 'children': [], 'value': '12.0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'jd'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ipart'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '57'], 'value': '/'},{'id': '48', 'type': '()', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '*'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1461'},{'id': '51', 'type': '()', 'children': ['52']},{'id': '52', 'type': 'binary_operator', 'children': ['53', '56'], 'value': '+'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '+'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '55', 'type': 'integer', 'children': [], 'value': '4800'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '57', 'type': 'float', 'children': [], 'value': '4.0'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'jd'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ipart'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '76'], 'value': '/'},{'id': '65', 'type': '()', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '*'},{'id': '67', 'type': 'integer', 'children': [], 'value': '367'},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '73'], 'value': '-'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '-'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '72', 'type': 'integer', 'children': [], 'value': '2'},{'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '*'},{'id': '74', 'type': 'integer', 'children': [], 'value': '12'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '76', 'type': 'float', 'children': [], 'value': '12.0'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ipart'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '90'], 'value': '/'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '89'], 'value': '+'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '+'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '88', 'type': 'integer', 'children': [], 'value': '4900'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '90', 'type': 'float', 'children': [], 'value': '100.0'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '-='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'jd'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ipart'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '102'], 'value': '/'},{'id': '98', 'type': '()', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '*'},{'id': '100', 'type': 'integer', 'children': [], 'value': '3'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'float', 'children': [], 'value': '4.0'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'augmented_assignment', 'children': ['105', '106'], 'value': '+='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'jd'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '-'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '108', 'type': 'float', 'children': [], 'value': '2432075.5'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '112'], 'value': '-='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'jd'},{'id': '112', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '113', 'type': 'return_statement', 'children': ['114']},{'id': '114', 'type': 'expression_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'MJD_0'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'jd'} | def gcal2jd(year, month, day):
year = int(year)
month = int(month)
day = int(day)
a = ipart((month - 14) / 12.0)
jd = ipart((1461 * (year + 4800 + a)) / 4.0)
jd += ipart((367 * (month - 2 - 12 * a)) / 12.0)
x = ipart((year + 4900 + a) / 100.0)
jd -= ipart((3 * x) / 4.0)
jd += day - 2432075.5
jd -= 0.5
return MJD_0, jd |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_restart_params'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'restart_strategy'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'min_beta'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 's_greedy'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'xi_restart'},{'id': '9', 'type': 'block', 'children': ['10', '12', '19', '33', '48', '62', '76']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'restart_strategy'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '25']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '!='},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '24', 'type': 'string', 'children': [], 'value': "'regular'"},{'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': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'concatenated_string', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'Restarting strategies can only be used with '"},{'id': '32', 'type': 'string', 'children': [], 'value': "'regular mode.'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'greedy_params_check'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '45'], 'value': 'or'},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'min_beta'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 's_greedy'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<='},{'id': '46', 'type': 'identifier', 'children': [], 'value': 's_greedy'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'and'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '=='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'restart_strategy'},{'id': '52', 'type': 'string', 'children': [], 'value': "'greedy'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'greedy_params_check'},{'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': 'concatenated_string', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'You need a min_beta and an s_greedy > 1 for '"},{'id': '61', 'type': 'string', 'children': [], 'value': "'greedy restart.'"},{'id': '62', 'type': 'if_statement', 'children': ['63', '70']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'or'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'xi_restart'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '>='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'xi_restart'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'raise_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'You need a xi_restart < 1 for restart.'"},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'True', 'children': []} | def _check_restart_params(self, restart_strategy, min_beta, s_greedy,
xi_restart):
r
if restart_strategy is None:
return True
if self.mode != 'regular':
raise ValueError('Restarting strategies can only be used with '
'regular mode.')
greedy_params_check = (min_beta is None or s_greedy is None or
s_greedy <= 1)
if restart_strategy == 'greedy' and greedy_params_check:
raise ValueError('You need a min_beta and an s_greedy > 1 for '
'greedy restart.')
if xi_restart is None or xi_restart >= 1:
raise ValueError('You need a xi_restart < 1 for restart.')
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'method_cache'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '6', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '9', 'type': 'string', 'children': [], 'value': "'run'"},{'id': '10', 'type': 'block', 'children': ['11', '243']},{'id': '11', 'type': 'function_definition', 'children': ['12', '13', '15']},{'id': '12', 'type': 'function_name', 'children': [], 'value': 'decorate_'},{'id': '13', 'type': 'parameters', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '15', 'type': 'block', 'children': ['16', '241']},{'id': '16', 'type': 'function_definition', 'children': ['17', '18', '23']},{'id': '17', 'type': 'function_name', 'children': [], 'value': 'decorate'},{'id': '18', 'type': 'parameters', 'children': ['19', '21']},{'id': '19', 'type': 'list_splat_pattern', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'dictionary_splat_pattern', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '23', 'type': 'block', 'children': ['24', '30', '39', '63', '81', '89', '167', '233']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'assert_statement', 'children': ['31', '36']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'},{'id': '37', 'type': 'string', 'children': [], 'value': '"Model must have a \'%s\' method."'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '39', 'type': 'if_statement', 'children': ['40', '45', '50']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'method_args'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'method_args'},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '59', '62'], 'value': 'if'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'in'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '62', 'type': 'dictionary', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '72']},{'id': '64', 'type': 'not_operator', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '71', 'type': 'string', 'children': [], 'value': "'cached_runs'"},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cached_runs'},{'id': '80', 'type': 'dictionary', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cached_runs'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93', '137', '160']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '92', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '93', 'type': 'block', 'children': ['94', '122']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'model_dict'},{'id': '97', 'type': 'dictionary_comprehension', 'children': ['98', '101', '115', '116']},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '105']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '116', 'type': 'if_clause', 'children': ['117']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '!='},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'method_signature'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'SciUnit'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dict_hash'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'dictionary', 'children': ['131', '134']},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'attrs'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'model_dict'},{'id': '134', 'type': 'pair', 'children': ['135', '136']},{'id': '135', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'method_args'},{'id': '137', 'type': 'elif_clause', 'children': ['138', '141']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '140', 'type': 'string', 'children': [], 'value': "'instance'"},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'method_signature'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'SciUnit'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dict_hash'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'dictionary', 'children': ['151', '157']},{'id': '151', 'type': 'pair', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '157', 'type': 'pair', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'method_args'},{'id': '160', 'type': 'else_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'raise_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': '"Cache type must be \'value\' or \'instance\'"'},{'id': '167', 'type': 'if_statement', 'children': ['168', '171', '209']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'not'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'method_signature'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '171', 'type': 'block', 'children': ['172', '177', '185', '191']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': '"Method with this signature not found in the cache. Running..."'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'dictionary_splat', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'method_args'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'method_signature'},{'id': '196', 'type': 'tuple', 'children': ['197', '202']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '201', 'type': 'argument_list', 'children': []},{'id': '202', 'type': 'call', 'children': ['203', '208']},{'id': '203', 'type': 'attribute', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '206', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '208', 'type': 'argument_list', 'children': []},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211', '216', '224']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'string', 'children': [], 'value': '"Method with this signature found in the cache. Restoring..."'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '221']},{'id': '218', 'type': 'pattern_list', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'method_signature'},{'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': 'model'},{'id': '229', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '236', 'type': 'argument_list', 'children': ['237', '239']},{'id': '237', 'type': 'list_splat', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '239', 'type': 'dictionary_splat', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'decorate'},{'id': '243', 'type': 'return_statement', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'decorate_'} | def method_cache(by='value',method='run'):
def decorate_(func):
def decorate(*args, **kwargs):
model = args[0]
assert hasattr(model,method), "Model must have a '%s' method."%method
if func.__name__ == method:
method_args = kwargs
else:
method_args = kwargs[method] if method in kwargs else {}
if not hasattr(model.__class__,'cached_runs'):
model.__class__.cached_runs = {}
cache = model.__class__.cached_runs
if by == 'value':
model_dict = {key:value for key,value in list(model.__dict__.items()) \
if key[0]!='_'}
method_signature = SciUnit.dict_hash({'attrs':model_dict,'args':method_args})
elif by == 'instance':
method_signature = SciUnit.dict_hash({'id':id(model),'args':method_args})
else:
raise ValueError("Cache type must be 'value' or 'instance'")
if method_signature not in cache:
print("Method with this signature not found in the cache. Running...")
f = getattr(model,method)
f(**method_args)
cache[method_signature] = (datetime.now(),model.__dict__.copy())
else:
print("Method with this signature found in the cache. Restoring...")
_,attrs = cache[method_signature]
model.__dict__.update(attrs)
return func(*args, **kwargs)
return decorate
return decorate_ |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_format_command'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'show_nested'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '21', '31', '41', '51', '61', '70', '77', '87', '96', '103', '113', '122', '129', '133', '141', '150']},{'id': '10', 'type': 'if_statement', 'children': ['11', '19']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '13', 'type': 'argument_list', 'children': ['14', '17', '18']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '17', 'type': 'string', 'children': [], 'value': "'hidden'"},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': []},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '27']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_format_description'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'yield', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'yield', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'.. program:: {}'"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'command_path'},{'id': '41', 'type': 'for_statement', 'children': ['42', '43', '47']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_format_usage'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'yield', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lines'},{'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': '_format_options'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '61', 'type': 'if_statement', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '63', 'type': 'block', 'children': ['64', '67']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'yield', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': "'.. rubric:: Options'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'yield', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "''"},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'yield', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_format_arguments'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '87', 'type': 'if_statement', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '89', 'type': 'block', 'children': ['90', '93']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'yield', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'.. rubric:: Arguments'"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'yield', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "''"},{'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'yield', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_format_envvars'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '113', 'type': 'if_statement', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '115', 'type': 'block', 'children': ['116', '119']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'yield', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': "'.. rubric:: Environment variables'"},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'yield', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "''"},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'yield', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '129', 'type': 'if_statement', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'show_nested'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'return_statement', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_filter_commands'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '141', 'type': 'if_statement', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '143', 'type': 'block', 'children': ['144', '147']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'yield', 'children': ['146']},{'id': '146', 'type': 'string', 'children': [], 'value': "'.. rubric:: Commands'"},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'yield', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "''"},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '153', 'type': 'block', 'children': ['154', '167', '177']},{'id': '154', 'type': 'if_statement', 'children': ['155', '160']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '>='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'CLICK_VERSION'},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'integer', 'children': [], 'value': '7'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'if_statement', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'continue_statement', 'children': []},{'id': '167', 'type': 'for_statement', 'children': ['168', '169', '173']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_format_subcommand'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'yield', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'yield', 'children': ['179']},{'id': '179', 'type': 'string', 'children': [], 'value': "''"} | def _format_command(ctx, show_nested, commands=None):
if getattr(ctx.command, 'hidden', False):
return
for line in _format_description(ctx):
yield line
yield '.. program:: {}'.format(ctx.command_path)
for line in _format_usage(ctx):
yield line
lines = list(_format_options(ctx))
if lines:
yield '.. rubric:: Options'
yield ''
for line in lines:
yield line
lines = list(_format_arguments(ctx))
if lines:
yield '.. rubric:: Arguments'
yield ''
for line in lines:
yield line
lines = list(_format_envvars(ctx))
if lines:
yield '.. rubric:: Environment variables'
yield ''
for line in lines:
yield line
if show_nested:
return
commands = _filter_commands(ctx, commands)
if commands:
yield '.. rubric:: Commands'
yield ''
for command in commands:
if CLICK_VERSION >= (7, 0):
if command.hidden:
continue
for line in _format_subcommand(command):
yield line
yield '' |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_formatter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'block', 'children': ['23', '53', '77', '87', '139', '191', '195', '257', '280', '307', '341']},{'id': '23', 'type': 'function_definition', 'children': ['24', '25', '27']},{'id': '24', 'type': 'function_name', 'children': [], 'value': 'is_date'},{'id': '25', 'type': 'parameters', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '27', 'type': 'block', 'children': ['28', '36']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_major_formatter'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '46'], 'value': 'or'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mdates'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'DateFormatter'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'mdates'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'AutoDateFormatter'},{'id': '53', 'type': 'function_definition', 'children': ['54', '55', '57']},{'id': '54', 'type': 'function_name', 'children': [], 'value': 'format_date'},{'id': '55', 'type': 'parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '62']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '73']},{'id': '65', 'type': 'attribute', 'children': ['66', '72']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mdates'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'num2date'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'date_format'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '80', 'type': 'attribute', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '84', 'type': 'string', 'children': [], 'value': "'event'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'artist'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '87', 'type': 'if_statement', 'children': ['88', '94', '102']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'is_date'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'xaxis'},{'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': 'x'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'format_date'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'else_clause', 'children': ['103']},{'id': '103', 'type': 'block', 'children': ['104', '112', '122']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'get_xlim'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': '_format_coord'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '126', 'type': 'string', 'children': [], 'value': "'xerror'"},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': '_format_coord'},{'id': '131', 'type': 'argument_list', 'children': ['132', '138']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': "'xerror'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '139', 'type': 'if_statement', 'children': ['140', '146', '154']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'is_date'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'yaxis'},{'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': 'y'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'format_date'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156', '164', '174']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get_ylim'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_format_coord'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '178', 'type': 'string', 'children': [], 'value': "'yerror'"},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': '_format_coord'},{'id': '183', 'type': 'argument_list', 'children': ['184', '190']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': "'yerror'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'limits'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '194', 'type': 'list', 'children': [], 'value': '[]'},{'id': '195', 'type': 'for_statement', 'children': ['196', '199', '212']},{'id': '196', 'type': 'pattern_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '201', 'type': 'argument_list', 'children': ['202', '207']},{'id': '202', 'type': 'list', 'children': ['203', '204', '205', '206'], 'value': "['x', 'y', 'z', 's']"},{'id': '203', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '204', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '205', 'type': 'string', 'children': [], 'value': "'z'"},{'id': '206', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '207', 'type': 'list', 'children': ['208', '209', '210', '211'], 'value': '[x, y, z, s]'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '216', 'type': 'None', 'children': []},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'try_statement', 'children': ['219', '237']},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': "u'{key}: {val:0.3g}'"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '230', 'type': 'argument_list', 'children': ['231', '234']},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '237', 'type': 'except_clause', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'string', 'children': [], 'value': "u'{key}: {val}'"},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '250', 'type': 'argument_list', 'children': ['251', '254']},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '257', 'type': 'if_statement', 'children': ['258', '267']},{'id': '258', 'type': 'boolean_operator', 'children': ['259', '260'], 'value': 'and'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '260', 'type': 'not_operator', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "u'Label: {}'"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '280', 'type': 'if_statement', 'children': ['281', '290']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '289'], 'value': 'is'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': "u'point_label'"},{'id': '288', 'type': 'None', 'children': []},{'id': '289', 'type': 'None', 'children': []},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'},{'id': '298', 'type': 'string', 'children': [], 'value': "u'Point: '"},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'string', 'children': [], 'value': "u', '"},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '306', 'type': 'string', 'children': [], 'value': "'point_label'"},{'id': '307', 'type': 'for_statement', 'children': ['308', '309', '312']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '309', 'type': 'list', 'children': ['310', '311'], 'value': "['xerror', 'yerror']"},{'id': '310', 'type': 'string', 'children': [], 'value': "'xerror'"},{'id': '311', 'type': 'string', 'children': [], 'value': "'yerror'"},{'id': '312', 'type': 'block', 'children': ['313', '323']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '320', 'type': 'argument_list', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '322', 'type': 'None', 'children': []},{'id': '323', 'type': 'if_statement', 'children': ['324', '327']},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '326'], 'value': 'is'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '326', 'type': 'None', 'children': []},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'string', 'children': [], 'value': "u'{}: {}'"},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '338', 'type': 'argument_list', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '341', 'type': 'return_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': "u'\\n'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'output'} | def _formatter(self, x=None, y=None, z=None, s=None, label=None, **kwargs):
def is_date(axis):
fmt = axis.get_major_formatter()
return (isinstance(fmt, mdates.DateFormatter)
or isinstance(fmt, mdates.AutoDateFormatter))
def format_date(num):
if num is not None:
return mdates.num2date(num).strftime(self.date_format)
ax = kwargs['event'].artist.axes
if is_date(ax.xaxis):
x = format_date(x)
else:
limits = ax.get_xlim()
x = self._format_coord(x, limits)
kwargs['xerror'] = self._format_coord(kwargs.get('xerror'), limits)
if is_date(ax.yaxis):
y = format_date(y)
else:
limits = ax.get_ylim()
y = self._format_coord(y, limits)
kwargs['yerror'] = self._format_coord(kwargs.get('yerror'), limits)
output = []
for key, val in zip(['x', 'y', 'z', 's'], [x, y, z, s]):
if val is not None:
try:
output.append(u'{key}: {val:0.3g}'.format(key=key, val=val))
except ValueError:
output.append(u'{key}: {val}'.format(key=key, val=val))
if label and not label.startswith('_'):
output.append(u'Label: {}'.format(label))
if kwargs.get(u'point_label', None) is not None:
output.append(u'Point: ' + u', '.join(kwargs['point_label']))
for arg in ['xerror', 'yerror']:
val = kwargs.get(arg, None)
if val is not None:
output.append(u'{}: {}'.format(arg, val))
return u'\n'.join(output) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'datacursor'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '12', 'type': 'block', 'children': ['13', '43', '83', '97', '116']},{'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']},{'id': '14', 'type': 'function_name', 'children': [], 'value': 'plotted_artists'},{'id': '15', 'type': 'parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '17', 'type': 'block', 'children': ['18', '41']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '21', 'type': '()', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '38'], 'value': '+'},{'id': '23', 'type': 'binary_operator', 'children': ['24', '35'], 'value': '+'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '32'], 'value': '+'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '29'], 'value': '+'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'patches'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'images'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'containers'},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48', '58', '70']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'managers'},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pylab_helpers'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Gcf'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get_all_fig_managers'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'figs'},{'id': '61', 'type': 'list_comprehension', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'manager'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '67', 'type': 'for_in_clause', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'manager'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'managers'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '73', 'type': 'list_comprehension', 'children': ['74', '75', '78']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'figs'},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '83', 'type': 'if_statement', 'children': ['84', '91']},{'id': '84', 'type': 'not_operator', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cbook'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '95', 'type': 'list', 'children': ['96'], 'value': '[axes]'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '105', 'type': 'list_comprehension', 'children': ['106', '107', '110']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'artist'},{'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '110', 'type': 'for_in_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'artist'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'plotted_artists'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'DataCursor'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'artists'},{'id': '121', 'type': 'dictionary_splat', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def datacursor(artists=None, axes=None, **kwargs):
def plotted_artists(ax):
artists = (ax.lines + ax.patches + ax.collections
+ ax.images + ax.containers)
return artists
if axes is None:
managers = pylab_helpers.Gcf.get_all_fig_managers()
figs = [manager.canvas.figure for manager in managers]
axes = [ax for fig in figs for ax in fig.axes]
if not cbook.iterable(axes):
axes = [axes]
if artists is None:
artists = [artist for ax in axes for artist in plotted_artists(ax)]
return DataCursor(artists, **kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_for_notification'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'delegate'},{'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'notification_timeout'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '14', 'type': 'block', 'children': ['15', '28', '32', '36', '46', '288']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_connected'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'BluetoothBackendException'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'Not connected to any device.'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '35', 'type': 'integer', 'children': [], 'value': '10'},{'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': '_LOGGER'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': '"Enter write_ble (%s)"'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'current_thread'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'while_statement', 'children': ['47', '52']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '52', 'type': 'block', 'children': ['53', '84', '93', '172', '186', '201', '209', '258', '262', '270']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"gatttool --device={} --addr-type={} --char-write-req -a {} -n {} --adapter={} --listen"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64', '67', '73', '81']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_mac'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'address_type'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'byte_to_handle'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'bytes_to_string'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_DATA_MODE_LISTEN'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'adapter'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92']},{'id': '90', 'type': 'string', 'children': [], 'value': '"Running gatttool with a timeout of %d: %s"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'notification_timeout'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '93', 'type': 'with_statement', 'children': ['94', '117']},{'id': '94', 'type': 'with_clause', 'children': ['95']},{'id': '95', 'type': 'with_item', 'children': ['96']},{'id': '96', 'type': 'as_pattern', 'children': ['97', '115']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '104', '107', '110']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '103', 'type': 'True', 'children': []},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'preexec_fn'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'setsid'},{'id': '115', 'type': 'as_pattern_target', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'try_statement', 'children': ['119', '140']},{'id': '119', 'type': 'block', 'children': ['120', '133']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '123', 'type': 'subscript', 'children': ['124', '132']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'notification_timeout'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': '"Finished gatttool"'},{'id': '140', 'type': 'except_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'TimeoutExpired'},{'id': '142', 'type': 'block', 'children': ['143', '155', '165']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'killpg'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'SIGINT'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '158', 'type': 'subscript', 'children': ['159', '164']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'integer', 'children': [], 'value': '0'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': '"Listening stopped forcefully after timeout."'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '175', 'type': 'call', 'children': ['176', '184']},{'id': '176', 'type': 'attribute', 'children': ['177', '183']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "' \\n\\t'"},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'in'},{'id': '188', 'type': 'string', 'children': [], 'value': '"Write Request failed"'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'raise_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'BluetoothBackendException'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "'Error writing handle to sensor: {}'"},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': '_LOGGER'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': '"Got %s from gatttool"'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '209', 'type': 'if_statement', 'children': ['210', '213']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'in'},{'id': '211', 'type': 'string', 'children': [], 'value': '"successfully"'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '213', 'type': 'block', 'children': ['214', '224', '256']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': '"Exit write_ble with result (%s)"'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'current_thread'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'for_statement', 'children': ['225', '226', '232']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'element'},{'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': 'extract_notification_payload'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'delegate'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'handleNotification'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'list_comprehension', 'children': ['244', '249']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '248', 'type': 'integer', 'children': [], 'value': '16'},{'id': '249', 'type': 'for_in_clause', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'return_statement', 'children': ['257']},{'id': '257', 'type': 'True', 'children': []},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'augmented_assignment', 'children': ['260', '261'], 'value': '+='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '261', 'type': 'integer', 'children': [], 'value': '1'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': '"Waiting for %s seconds before retrying"'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '270', 'type': 'if_statement', 'children': ['271', '276']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': '<'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '276', 'type': 'block', 'children': ['277', '284']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'augmented_assignment', 'children': ['286', '287'], 'value': '*='},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'delay'},{'id': '287', 'type': 'integer', 'children': [], 'value': '2'},{'id': '288', 'type': 'raise_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'BluetoothBackendException'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'string', 'children': [], 'value': '"Exit write_ble, no data ({})"'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'current_thread'},{'id': '299', 'type': 'argument_list', 'children': []} | def wait_for_notification(self, handle: int, delegate, notification_timeout: float):
if not self.is_connected():
raise BluetoothBackendException('Not connected to any device.')
attempt = 0
delay = 10
_LOGGER.debug("Enter write_ble (%s)", current_thread())
while attempt <= self.retries:
cmd = "gatttool --device={} --addr-type={} --char-write-req -a {} -n {} --adapter={} --listen".format(
self._mac, self.address_type, self.byte_to_handle(handle), self.bytes_to_string(self._DATA_MODE_LISTEN),
self.adapter)
_LOGGER.debug("Running gatttool with a timeout of %d: %s", notification_timeout, cmd)
with Popen(cmd,
shell=True,
stdout=PIPE,
stderr=PIPE,
preexec_fn=os.setsid) as process:
try:
result = process.communicate(timeout=notification_timeout)[0]
_LOGGER.debug("Finished gatttool")
except TimeoutExpired:
os.killpg(process.pid, signal.SIGINT)
result = process.communicate()[0]
_LOGGER.debug("Listening stopped forcefully after timeout.")
result = result.decode("utf-8").strip(' \n\t')
if "Write Request failed" in result:
raise BluetoothBackendException('Error writing handle to sensor: {}'.format(result))
_LOGGER.debug("Got %s from gatttool", result)
if "successfully" in result:
_LOGGER.debug("Exit write_ble with result (%s)", current_thread())
for element in self.extract_notification_payload(result):
delegate.handleNotification(handle, bytes([int(x, 16) for x in element.split()]))
return True
attempt += 1
_LOGGER.debug("Waiting for %s seconds before retrying", delay)
if attempt < self.retries:
time.sleep(delay)
delay *= 2
raise BluetoothBackendException("Exit write_ble, no data ({})".format(current_thread())) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'simplify_tree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'in_list'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '188']},{'id': '12', 'type': 'if_statement', 'children': ['13', '25', '132', '154']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '19'], 'value': 'and'},{'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': 'tree'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'BaseNode'},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Terminal'},{'id': '25', 'type': 'block', 'children': ['26', '43', '67', '128']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'used_fields'},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '31', '36']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_fields'},{'id': '36', 'type': 'if_clause', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '42', 'type': 'False', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '50', '61']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '49'], 'value': '=='},{'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': 'used_fields'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'used_fields'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '90']},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'boolean_operator', 'children': ['70', '82'], 'value': 'or'},{'id': '70', 'type': 'boolean_operator', 'children': ['71', '77'], 'value': 'or'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '!='},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'used_fields'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'tree'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'AliasNode'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '85'], 'value': 'and'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'in_list'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '90', 'type': 'block', 'children': ['91', '95', '126']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '100']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_fields'},{'id': '100', 'type': 'block', 'children': ['101', '110']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'old_value'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'old_value'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'simplify_tree'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'old_value'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '128', 'type': 'assert_statement', 'children': ['129']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'elif_clause', 'children': ['133', '147']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '146'], 'value': 'and'},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '140'], 'value': 'and'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '145'], 'value': '=='},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156', '186']},{'id': '156', 'type': 'if_statement', 'children': ['157', '162', '180']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '166', 'type': 'list_comprehension', 'children': ['167', '177']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'simplify_tree'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '174']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'in_list'},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'simplify_tree'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'unpack_lists'} | def simplify_tree(tree, unpack_lists=True, in_list=False):
if isinstance(tree, BaseNode) and not isinstance(tree, Terminal):
used_fields = [field for field in tree._fields if getattr(tree, field, False)]
if len(used_fields) == 1:
result = getattr(tree, used_fields[0])
else:
result = None
if (
len(used_fields) != 1
or isinstance(tree, AliasNode)
or (in_list and isinstance(result, list))
):
result = tree
for field in tree._fields:
old_value = getattr(tree, field, None)
if old_value:
setattr(
result,
field,
simplify_tree(old_value, unpack_lists=unpack_lists),
)
return result
assert result is not None
elif isinstance(tree, list) and len(tree) == 1 and unpack_lists:
result = tree[0]
else:
if isinstance(tree, list):
result = [
simplify_tree(el, unpack_lists=unpack_lists, in_list=True)
for el in tree
]
else:
result = tree
return result
return simplify_tree(result, unpack_lists=unpack_lists) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '19', '30', '78']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'~/.sortinghat'"},{'id': '30', 'type': 'if_statement', 'children': ['31', '36', '49', '71']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': '=='},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '35', 'type': 'string', 'children': [], 'value': "'get'"},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'code'},{'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': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '55']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '=='},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '54', 'type': 'string', 'children': [], 'value': "'set'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67', '70']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"Not get or set action given"'},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'code'} | def run(self, *args):
params = self.parser.parse_args(args)
config_file = os.path.expanduser('~/.sortinghat')
if params.action == 'get':
code = self.get(params.parameter, config_file)
elif params.action == 'set':
code = self.set(params.parameter, params.value, config_file)
else:
raise RuntimeError("Not get or set action given")
return code |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'export'},{'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': 'source'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '27', '97', '114', '142']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'uids'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'unique_identities'},{'id': '20', 'type': 'argument_list', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'uids'},{'id': '30', 'type': 'block', 'children': ['31', '55', '63', '79', '87']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '34', 'type': 'list_comprehension', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '46', 'type': 'argument_list', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '68', 'type': 'string', 'children': [], 'value': "'identities'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'lambda', 'children': ['74', '76']},{'id': '74', 'type': 'lambda_parameters', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '78', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '86']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '96']},{'id': '89', 'type': 'subscript', 'children': ['90', '95']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '95', 'type': 'string', 'children': [], 'value': "'enrollments'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '100', 'type': 'list_comprehension', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'mb'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mb'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '117', 'type': 'dictionary', 'children': ['118', '130', '133', '136', '139']},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '129', 'type': 'argument_list', 'children': []},{'id': '130', 'type': 'pair', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '133', 'type': 'pair', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'blacklist'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'organizations'"},{'id': '138', 'type': 'dictionary', 'children': []},{'id': '139', 'type': 'pair', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'uidentities'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149', '154', '157', '162']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_json_encoder'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '156', 'type': 'integer', 'children': [], 'value': '4'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '159', 'type': 'tuple', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "','"},{'id': '161', 'type': 'string', 'children': [], 'value': "': '"},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '164', 'type': 'True', 'children': []} | def export(self, source=None):
uidentities = {}
uids = api.unique_identities(self.db, source=source)
for uid in uids:
enrollments = [rol.to_dict()
for rol in api.enrollments(self.db, uuid=uid.uuid)]
u = uid.to_dict()
u['identities'].sort(key=lambda x: x['id'])
uidentities[uid.uuid] = u
uidentities[uid.uuid]['enrollments'] = enrollments
blacklist = [mb.excluded for mb in api.blacklist(self.db)]
obj = {'time': str(datetime.datetime.now()),
'source': source,
'blacklist': blacklist,
'organizations': {},
'uidentities': uidentities}
return json.dumps(obj, default=self._json_encoder,
indent=4, separators=(',', ': '),
sort_keys=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'export'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '21', '67', '92']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'organizations'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'registry'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '24', 'type': 'block', 'children': ['25', '45', '59']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '40']},{'id': '29', 'type': 'dictionary', 'children': ['30', '35']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'domain'"},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'is_top'"},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'lambda', 'children': ['54', '56']},{'id': '54', 'type': 'lambda_parameters', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'string', 'children': [], 'value': "'domain'"},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '66']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'organizations'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '70', 'type': 'dictionary', 'children': ['71', '83', '86', '89']},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'blacklist'"},{'id': '85', 'type': 'list', 'children': [], 'value': '[]'},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'organizations'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'organizations'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'uidentities'"},{'id': '91', 'type': 'dictionary', 'children': []},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99', '104', '107', '112']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_json_encoder'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '106', 'type': 'integer', 'children': [], 'value': '4'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "','"},{'id': '111', 'type': 'string', 'children': [], 'value': "': '"},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '114', 'type': 'True', 'children': []} | def export(self):
organizations = {}
orgs = api.registry(self.db)
for org in orgs:
domains = [{'domain': dom.domain,
'is_top': dom.is_top_domain}
for dom in org.domains]
domains.sort(key=lambda x: x['domain'])
organizations[org.name] = domains
obj = {'time': str(datetime.datetime.now()),
'blacklist': [],
'organizations': organizations,
'uidentities': {}}
return json.dumps(obj, default=self._json_encoder,
indent=4, separators=(',', ': '),
sort_keys=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '7', 'type': 'block', 'children': ['8', '21', '34', '53', '62', '71', '90']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'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': 'ValueError'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"<a> is not an instance of UniqueIdentity"'},{'id': '21', 'type': 'if_statement', 'children': ['22', '28']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': '"<b> is not an instance of UniqueIdentity"'},{'id': '34', 'type': 'if_statement', 'children': ['35', '50']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '43'], 'value': 'and'},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'and'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '=='},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'filtered_a'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'filtered_b'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'filtered_a'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fb'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filtered_b'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'if_statement', 'children': ['80', '87']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'match_filtered_identities'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fb'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'True', 'children': []},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'False', 'children': []} | def match(self, a, b):
if not isinstance(a, UniqueIdentity):
raise ValueError("<a> is not an instance of UniqueIdentity")
if not isinstance(b, UniqueIdentity):
raise ValueError("<b> is not an instance of UniqueIdentity")
if a.uuid and b.uuid and a.uuid == b.uuid:
return True
filtered_a = self.filter(a)
filtered_b = self.filter(b)
for fa in filtered_a:
for fb in filtered_b:
if self.match_filtered_identities(fa, fb):
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_enrollments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'with_statement', 'children': ['9', '19']},{'id': '9', 'type': 'with_clause', 'children': ['10']},{'id': '10', 'type': 'with_item', 'children': ['11']},{'id': '11', 'type': 'as_pattern', 'children': ['12', '17']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'as_pattern_target', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '19', 'type': 'block', 'children': ['20', '28', '39', '47', '58', '86', '108', '122', '210']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'find_unique_identity'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '28', 'type': 'if_statement', 'children': ['29', '31']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'raise_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'find_organization'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '47', 'type': 'if_statement', 'children': ['48', '50']},{'id': '48', 'type': 'not_operator', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'raise_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '61', 'type': 'call', 'children': ['62', '85']},{'id': '62', 'type': 'attribute', 'children': ['63', '84']},{'id': '63', 'type': 'call', 'children': ['64', '73']},{'id': '64', 'type': 'attribute', 'children': ['65', '71', '72']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '71', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '73', 'type': 'argument_list', 'children': ['74', '79']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': '=='},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '83'], 'value': '=='},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '89']},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '89', 'type': 'block', 'children': ['90', '101']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'tuple', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '101', 'type': 'raise_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '119']},{'id': '112', 'type': 'tuple', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'enr'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'enr'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'enr'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '122', 'type': 'for_statement', 'children': ['123', '126', '132']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'merge_date_ranges'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '132', 'type': 'block', 'children': ['133', '152', '168', '184']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'is_dup'},{'id': '136', 'type': 'lambda', 'children': ['137', '141']},{'id': '137', 'type': 'lambda_parameters', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '147'], 'value': 'and'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': '=='},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '=='},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'filtered'},{'id': '155', 'type': 'list_comprehension', 'children': ['156', '157', '160']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '160', 'type': 'if_clause', 'children': ['161']},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'is_dup'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166', '167']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '168', 'type': 'if_statement', 'children': ['169', '178']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '174'], 'value': '!='},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filtered'},{'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': 'disjoint'},{'id': '178', 'type': 'block', 'children': ['179', '183']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'filtered'},{'id': '183', 'type': 'continue_statement', 'children': []},{'id': '184', 'type': 'try_statement', 'children': ['185', '199']},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'enroll_db'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191', '192', '193', '196']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '199', 'type': 'except_clause', 'children': ['200', '204']},{'id': '200', 'type': 'as_pattern', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '202', 'type': 'as_pattern_target', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'raise_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '210', 'type': 'for_statement', 'children': ['211', '212', '213']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'enr'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'disjoint'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'delete_enrollment_db'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'enr'} | def merge_enrollments(db, uuid, organization):
with db.connect() as session:
uidentity = find_unique_identity(session, uuid)
if not uidentity:
raise NotFoundError(entity=uuid)
org = find_organization(session, organization)
if not org:
raise NotFoundError(entity=organization)
disjoint = session.query(Enrollment).\
filter(Enrollment.uidentity == uidentity,
Enrollment.organization == org).all()
if not disjoint:
entity = '-'.join((uuid, organization))
raise NotFoundError(entity=entity)
dates = [(enr.start, enr.end) for enr in disjoint]
for st, en in utils.merge_date_ranges(dates):
is_dup = lambda x, st, en: x.start == st and x.end == en
filtered = [x for x in disjoint if not is_dup(x, st, en)]
if len(filtered) != len(disjoint):
disjoint = filtered
continue
try:
enroll_db(session, uidentity, org,
from_date=st, to_date=en)
except ValueError as e:
raise InvalidValueError(e)
for enr in disjoint:
delete_enrollment_db(session, enr) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'registry'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '106']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'with_statement', 'children': ['14', '24']},{'id': '14', 'type': 'with_clause', 'children': ['15']},{'id': '15', 'type': 'with_item', 'children': ['16']},{'id': '16', 'type': 'as_pattern', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'as_pattern_target', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '24', 'type': 'block', 'children': ['25', '100']},{'id': '25', 'type': 'if_statement', 'children': ['26', '27', '77']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '27', 'type': 'block', 'children': ['28', '66']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '31', 'type': 'call', 'children': ['32', '65']},{'id': '32', 'type': 'attribute', 'children': ['33', '64']},{'id': '33', 'type': 'call', 'children': ['34', '60']},{'id': '34', 'type': 'attribute', 'children': ['35', '58', '59']},{'id': '35', 'type': 'call', 'children': ['36', '45']},{'id': '36', 'type': 'attribute', 'children': ['37', '43', '44']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '43', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'like'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '57'], 'value': '+'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'},{'id': '55', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '57', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '58', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '69']},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '82', 'type': 'call', 'children': ['83', '99']},{'id': '83', 'type': 'attribute', 'children': ['84', '98']},{'id': '84', 'type': 'call', 'children': ['85', '94']},{'id': '85', 'type': 'attribute', 'children': ['86', '92', '93']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '92', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '99', 'type': 'argument_list', 'children': []},{'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': 'session'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'expunge_all'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'orgs'} | def registry(db, term=None):
orgs = []
with db.connect() as session:
if term:
orgs = session.query(Organization).\
filter(Organization.name.like('%' + term + '%')).\
order_by(Organization.name).all()
if not orgs:
raise NotFoundError(entity=term)
else:
orgs = session.query(Organization).\
order_by(Organization.name).all()
session.expunge_all()
return orgs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'domains'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '16', '193']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'doms'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'with_statement', 'children': ['17', '27']},{'id': '17', 'type': 'with_clause', 'children': ['18']},{'id': '18', 'type': 'with_item', 'children': ['19']},{'id': '19', 'type': 'as_pattern', 'children': ['20', '25']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'as_pattern_target', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '27', 'type': 'block', 'children': ['28', '187']},{'id': '28', 'type': 'if_statement', 'children': ['29', '30', '147']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '30', 'type': 'block', 'children': ['31', '39']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'find_domain'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '39', 'type': 'if_statement', 'children': ['40', '42', '140']},{'id': '40', 'type': 'not_operator', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '46', '54']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56', '74', '81', '109', '129']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_dot'},{'id': '59', 'type': 'lambda', 'children': ['60', '62']},{'id': '60', 'type': 'lambda_parameters', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '62', 'type': 'conditional_expression', 'children': ['63', '66', '73'], 'value': 'if'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'},{'id': '64', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'add_dot'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '84', 'type': 'call', 'children': ['85', '108']},{'id': '85', 'type': 'attribute', 'children': ['86', '107']},{'id': '86', 'type': 'call', 'children': ['87', '103']},{'id': '87', 'type': 'attribute', 'children': ['88', '102']},{'id': '88', 'type': 'call', 'children': ['89', '98']},{'id': '89', 'type': 'attribute', 'children': ['90', '96', '97']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '96', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'doms'},{'id': '112', 'type': 'list_comprehension', 'children': ['113', '114', '117']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tops'},{'id': '117', 'type': 'if_clause', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'add_dot'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '129', 'type': 'if_statement', 'children': ['130', '132']},{'id': '130', 'type': 'not_operator', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'doms'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'raise_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'doms'},{'id': '145', 'type': 'list', 'children': ['146'], 'value': '[dom]'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149', '158', '172']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '158', 'type': 'if_statement', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'top'},{'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': 'query'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'doms'},{'id': '175', 'type': 'call', 'children': ['176', '186']},{'id': '176', 'type': 'attribute', 'children': ['177', '185']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '186', 'type': 'argument_list', 'children': []},{'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': 'session'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'expunge_all'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'return_statement', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'doms'} | def domains(db, domain=None, top=False):
doms = []
with db.connect() as session:
if domain:
dom = find_domain(session, domain)
if not dom:
if not top:
raise NotFoundError(entity=domain)
else:
add_dot = lambda d: '.' + d if not d.startswith('.') else d
d = add_dot(domain)
tops = session.query(Domain).\
filter(Domain.is_top_domain).order_by(Domain.domain).all()
doms = [t for t in tops
if d.endswith(add_dot(t.domain))]
if not doms:
raise NotFoundError(entity=domain)
else:
doms = [dom]
else:
query = session.query(Domain)
if top:
query = query.filter(Domain.is_top_domain)
doms = query.order_by(Domain.domain).all()
session.expunge_all()
return doms |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'countries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '39', '60', '64', '195']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': '_is_code_valid'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '33', '34'], 'value': 'and'},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '26', '27'], 'value': 'and'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '26', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '=='},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '32', 'type': 'integer', 'children': [], 'value': '2'},{'id': '33', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'isalpha'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '49']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_is_code_valid'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'raise_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': "'country code must be a 2 length alpha string - %s given'"},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cs'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'with_statement', 'children': ['65', '75']},{'id': '65', 'type': 'with_clause', 'children': ['66']},{'id': '66', 'type': 'with_item', 'children': ['67']},{'id': '67', 'type': 'as_pattern', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'as_pattern_target', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '75', 'type': 'block', 'children': ['76', '85', '189']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '85', 'type': 'if_statement', 'children': ['86', '89', '166']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '88'], 'value': 'or'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '89', 'type': 'block', 'children': ['90', '133', '148']},{'id': '90', 'type': 'if_statement', 'children': ['91', '92', '110']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '=='},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'elif_clause', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'like'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '132'], 'value': '+'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '+'},{'id': '130', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '132', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'cs'},{'id': '136', 'type': 'call', 'children': ['137', '147']},{'id': '137', 'type': 'attribute', 'children': ['138', '146']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'if_statement', 'children': ['149', '151']},{'id': '149', 'type': 'not_operator', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cs'},{'id': '151', 'type': 'block', 'children': ['152', '159']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '155', 'type': 'conditional_expression', 'children': ['156', '157', '158'], 'value': 'if'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '159', 'type': 'raise_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cs'},{'id': '171', 'type': 'call', 'children': ['172', '188']},{'id': '172', 'type': 'attribute', 'children': ['173', '187']},{'id': '173', 'type': 'call', 'children': ['174', '183']},{'id': '174', 'type': 'attribute', 'children': ['175', '181', '182']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '181', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Country'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'expunge_all'},{'id': '194', 'type': 'argument_list', 'children': []},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'cs'} | def countries(db, code=None, term=None):
def _is_code_valid(code):
return type(code) == str \
and len(code) == 2 \
and code.isalpha()
if code is not None and not _is_code_valid(code):
raise InvalidValueError('country code must be a 2 length alpha string - %s given'
% str(code))
cs = []
with db.connect() as session:
query = session.query(Country)
if code or term:
if code:
query = query.filter(Country.code == code.upper())
elif term:
query = query.filter(Country.name.like('%' + term + '%'))
cs = query.order_by(Country.code).all()
if not cs:
e = code if code else term
raise NotFoundError(entity=e)
else:
cs = session.query(Country).\
order_by(Country.code).all()
session.expunge_all()
return cs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'enrollments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '26', '34', '53', '72', '90', '94', '237']},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '26', 'type': 'if_statement', 'children': ['27', '29']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'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': 'to_date'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '34', 'type': 'if_statement', 'children': ['35', '42']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '39'], 'value': 'or'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '<'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '>'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'raise_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': '"\'from_date\' %s is out of bounds"'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '53', 'type': 'if_statement', 'children': ['54', '61']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '58'], 'value': 'or'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '<'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '>'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'raise_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '%'},{'id': '67', 'type': 'string', 'children': [], 'value': '"\'to_date\' %s is out of bounds"'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '72', 'type': 'if_statement', 'children': ['73', '80']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '77'], 'value': 'and'},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '76'], 'value': 'and'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '>'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'raise_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'},{'id': '86', 'type': 'string', 'children': [], 'value': '"\'from_date\' %s cannot be greater than %s"'},{'id': '87', 'type': 'tuple', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '93', 'type': 'list', 'children': [], 'value': '[]'},{'id': '94', 'type': 'with_statement', 'children': ['95', '105']},{'id': '95', 'type': 'with_clause', 'children': ['96']},{'id': '96', 'type': 'with_item', 'children': ['97']},{'id': '97', 'type': 'as_pattern', 'children': ['98', '103']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '105', 'type': 'block', 'children': ['106', '137', '172', '207', '231']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '109', 'type': 'call', 'children': ['110', '126']},{'id': '110', 'type': 'attribute', 'children': ['111', '124', '125']},{'id': '111', 'type': 'call', 'children': ['112', '121']},{'id': '112', 'type': 'attribute', 'children': ['113', '119', '120']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '119', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '124', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '126', 'type': 'argument_list', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '>='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '<='},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'to_date'},{'id': '137', 'type': 'if_statement', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '139', 'type': 'block', 'children': ['140', '148', '159']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'find_unique_identity'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '148', 'type': 'if_statement', 'children': ['149', '151']},{'id': '149', 'type': 'not_operator', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'raise_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '171'], 'value': '=='},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'uidentity'},{'id': '172', 'type': 'if_statement', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '174', 'type': 'block', 'children': ['175', '183', '194']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'find_organization'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '183', 'type': 'if_statement', 'children': ['184', '186']},{'id': '184', 'type': 'not_operator', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'raise_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '206'], 'value': '=='},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '210', 'type': 'call', 'children': ['211', '230']},{'id': '211', 'type': 'attribute', 'children': ['212', '229']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220', '223', '226']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'expunge_all'},{'id': '236', 'type': 'argument_list', 'children': []},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'enrollments'} | def enrollments(db, uuid=None, organization=None, from_date=None, to_date=None):
if not from_date:
from_date = MIN_PERIOD_DATE
if not to_date:
to_date = MAX_PERIOD_DATE
if from_date < MIN_PERIOD_DATE or from_date > MAX_PERIOD_DATE:
raise InvalidValueError("'from_date' %s is out of bounds" % str(from_date))
if to_date < MIN_PERIOD_DATE or to_date > MAX_PERIOD_DATE:
raise InvalidValueError("'to_date' %s is out of bounds" % str(to_date))
if from_date and to_date and from_date > to_date:
raise InvalidValueError("'from_date' %s cannot be greater than %s"
% (from_date, to_date))
enrollments = []
with db.connect() as session:
query = session.query(Enrollment).\
join(UniqueIdentity, Organization).\
filter(Enrollment.start >= from_date,
Enrollment.end <= to_date)
if uuid:
uidentity = find_unique_identity(session, uuid)
if not uidentity:
raise NotFoundError(entity=uuid)
query = query.filter(Enrollment.uidentity == uidentity)
if organization:
org = find_organization(session, organization)
if not org:
raise NotFoundError(entity=organization)
query = query.filter(Enrollment.organization == org)
enrollments = query.order_by(UniqueIdentity.uuid,
Organization.name,
Enrollment.start,
Enrollment.end).all()
session.expunge_all()
return enrollments |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'blacklist'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '106']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'mbs'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'with_statement', 'children': ['14', '24']},{'id': '14', 'type': 'with_clause', 'children': ['15']},{'id': '15', 'type': 'with_item', 'children': ['16']},{'id': '16', 'type': 'as_pattern', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'connect'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'as_pattern_target', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '24', 'type': 'block', 'children': ['25', '100']},{'id': '25', 'type': 'if_statement', 'children': ['26', '27', '77']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '27', 'type': 'block', 'children': ['28', '66']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mbs'},{'id': '31', 'type': 'call', 'children': ['32', '65']},{'id': '32', 'type': 'attribute', 'children': ['33', '64']},{'id': '33', 'type': 'call', 'children': ['34', '60']},{'id': '34', 'type': 'attribute', 'children': ['35', '58', '59']},{'id': '35', 'type': 'call', 'children': ['36', '45']},{'id': '36', 'type': 'attribute', 'children': ['37', '43', '44']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '43', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'like'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '57'], 'value': '+'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '+'},{'id': '55', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '57', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '58', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '69']},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mbs'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'mbs'},{'id': '82', 'type': 'call', 'children': ['83', '99']},{'id': '83', 'type': 'attribute', 'children': ['84', '98']},{'id': '84', 'type': 'call', 'children': ['85', '94']},{'id': '85', 'type': 'attribute', 'children': ['86', '92', '93']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '92', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '99', 'type': 'argument_list', 'children': []},{'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': 'session'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'expunge_all'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mbs'} | def blacklist(db, term=None):
mbs = []
with db.connect() as session:
if term:
mbs = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded.like('%' + term + '%')).\
order_by(MatchingBlacklist.excluded).all()
if not mbs:
raise NotFoundError(entity=term)
else:
mbs = session.query(MatchingBlacklist).\
order_by(MatchingBlacklist.excluded).all()
session.expunge_all()
return mbs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_identities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '6', 'type': 'block', 'children': ['7', '96', '105', '109']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '13']},{'id': '8', 'type': 'function_name', 'children': [], 'value': '__create_sh_identities'},{'id': '9', 'type': 'parameters', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'yaml_entry'},{'id': '13', 'type': 'block', 'children': ['14', '18', '35', '59', '94']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '35', 'type': 'if_statement', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '50', 'type': 'argument_list', 'children': ['51', '54']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'PERCEVAL_BACKENDS'},{'id': '62', 'type': 'block', 'children': ['63', '69']},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'yaml_entry'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'continue_statement', 'children': []},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '74']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'yaml_entry'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '74', 'type': 'block', 'children': ['75', '87']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84']},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pb'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'yaml_file'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '__load_yml'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'yid_counter'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'try_statement', 'children': ['110', '264']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'yaml_file'},{'id': '114', 'type': 'block', 'children': ['115', '121', '131', '139', '149', '159', '175', '185', '192', '196', '205', '217', '223', '232', '238', '256']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '120', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '137', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '138', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'is_bot'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'is_bot'"},{'id': '148', 'type': 'False', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'if_statement', 'children': ['160', '165']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '162'], 'value': 'and'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'email_validation'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '__validate_email'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': "'enrollments'"},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'yid_counter'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'augmented_assignment', 'children': ['194', '195'], 'value': '+='},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'yid_counter'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'prf'},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Profile'},{'id': '210', 'type': 'argument_list', 'children': ['211', '214']},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'is_bot'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'is_bot'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'prf'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'sh_identities'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': '__create_sh_identities'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'emails'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'yid'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'augmented_assignment', 'children': ['234', '237'], 'value': '+='},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sh_identities'},{'id': '238', 'type': 'if_statement', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '240', 'type': 'block', 'children': ['241', '250']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'affiliations'},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': '__parse_affiliations_yml'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'augmented_assignment', 'children': ['252', '255'], 'value': '+='},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'affiliations'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '263']},{'id': '258', 'type': 'subscript', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '264', 'type': 'except_clause', 'children': ['265', '269']},{'id': '265', 'type': 'as_pattern', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '267', 'type': 'as_pattern_target', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '269', 'type': 'block', 'children': ['270', '278', '289']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'string', 'children': [], 'value': '"Attribute %s not found"'},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '285'], 'value': '%'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '285', 'type': 'dictionary', 'children': ['286']},{'id': '286', 'type': 'pair', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '289', 'type': 'raise_statement', 'children': ['290']},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'msg'} | def __parse_identities(self, stream):
def __create_sh_identities(name, emails, yaml_entry):
ids = []
ids.append(Identity(name=name, source=self.source))
if emails:
for m in emails:
ids.append(Identity(email=m, source=self.source))
for pb in PERCEVAL_BACKENDS:
if pb not in yaml_entry:
continue
for username in yaml_entry[pb]:
identity = Identity(username=username, source=pb)
ids.append(identity)
return ids
yaml_file = self.__load_yml(stream)
yid_counter = 0
try:
for yid in yaml_file:
profile = yid['profile']
if profile is None:
raise AttributeError('profile')
name = yid['profile']['name']
is_bot = profile.get('is_bot', False)
emails = yid.get('email', None)
if emails and self.email_validation:
self.__validate_email(emails[0])
enrollments = yid.get('enrollments', None)
uuid = str(yid_counter)
yid_counter += 1
uid = UniqueIdentity(uuid=uuid)
prf = Profile(name=name, is_bot=is_bot)
uid.profile = prf
sh_identities = __create_sh_identities(name, emails, yid)
uid.identities += sh_identities
if enrollments:
affiliations = self.__parse_affiliations_yml(enrollments)
uid.enrollments += affiliations
self._identities[uuid] = uid
except KeyError as e:
error = "Attribute %s not found" % e.args
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_organizations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '6', 'type': 'block', 'children': ['7', '12', '21']},{'id': '7', 'type': 'if_statement', 'children': ['8', '10']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'yaml_file'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '__load_yml'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '21', 'type': 'try_statement', 'children': ['22', '176', '208']},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'yaml_file'},{'id': '26', 'type': 'block', 'children': ['27', '38', '64', '73', '168']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '__encode'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '37', 'type': 'string', 'children': [], 'value': "'organization'"},{'id': '38', 'type': 'if_statement', 'children': ['39', '41']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'block', 'children': ['42', '46', '57']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '45', 'type': 'string', 'children': [], 'value': '"Empty organization name"'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '%'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '53', 'type': 'dictionary', 'children': ['54']},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '73', 'type': 'if_statement', 'children': ['74', '77']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'string', 'children': [], 'value': "'domains'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '77', 'type': 'block', 'children': ['78', '112']},{'id': '78', 'type': 'if_statement', 'children': ['79', '87']},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '82', 'type': 'argument_list', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '85', 'type': 'string', 'children': [], 'value': "'domains'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '87', 'type': 'block', 'children': ['88', '94', '105']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '%'},{'id': '92', 'type': 'string', 'children': [], 'value': '"List of elements expected for organization %s"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '101'], 'value': '%'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '101', 'type': 'dictionary', 'children': ['102']},{'id': '102', 'type': 'pair', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '105', 'type': 'raise_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '117']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '116', 'type': 'string', 'children': [], 'value': "'domains'"},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'if_statement', 'children': ['119', '120', '142']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '120', 'type': 'block', 'children': ['121', '133']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '126', 'type': 'argument_list', 'children': ['127', '130']},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '132', 'type': 'False', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144', '150', '161']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '%'},{'id': '148', 'type': 'string', 'children': [], 'value': '"Empty domain name for organization %s"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '%'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '157', 'type': 'dictionary', 'children': ['158']},{'id': '158', 'type': 'pair', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '161', 'type': 'raise_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '175']},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_organizations'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '176', 'type': 'except_clause', 'children': ['177', '181']},{'id': '177', 'type': 'as_pattern', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '179', 'type': 'as_pattern_target', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '181', 'type': 'block', 'children': ['182', '190', '201']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'},{'id': '186', 'type': 'string', 'children': [], 'value': '"Attribute %s not found"'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '%'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '197', 'type': 'dictionary', 'children': ['198']},{'id': '198', 'type': 'pair', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '201', 'type': 'raise_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '208', 'type': 'except_clause', 'children': ['209', '213']},{'id': '209', 'type': 'as_pattern', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '211', 'type': 'as_pattern_target', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '213', 'type': 'block', 'children': ['214', '222', '233']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'},{'id': '218', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '229'], 'value': '%'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'GRIMOIRELAB_INVALID_FORMAT'},{'id': '229', 'type': 'dictionary', 'children': ['230']},{'id': '230', 'type': 'pair', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '233', 'type': 'raise_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'msg'} | def __parse_organizations(self, stream):
if not stream:
return
yaml_file = self.__load_yml(stream)
try:
for element in yaml_file:
name = self.__encode(element['organization'])
if not name:
error = "Empty organization name"
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg)
o = Organization(name=name)
if 'domains' in element:
if not isinstance(element['domains'], list):
error = "List of elements expected for organization %s" % name
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg)
for dom in element['domains']:
if dom:
d = Domain(domain=dom, is_top_domain=False)
o.domains.append(d)
else:
error = "Empty domain name for organization %s" % name
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg)
self._organizations[name] = o
except KeyError as e:
error = "Attribute %s not found" % e.args
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg)
except TypeError as e:
error = "%s" % e.args
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
raise InvalidFormatError(cause=msg) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '6', 'type': 'block', 'children': ['7', '18', '27', '34', '41']},{'id': '7', 'type': 'if_statement', 'children': ['8', '10']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'raise_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '17', 'type': 'string', 'children': [], 'value': '"stream cannot be empty or None"'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'json'},{'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': '__load_json'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '__parse_organizations'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '__parse_identities'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'json'},{'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': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '__parse_blacklist'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'json'} | def __parse(self, stream):
if not stream:
raise InvalidFormatError(cause="stream cannot be empty or None")
json = self.__load_json(stream)
self.__parse_organizations(json)
self.__parse_identities(json)
self.__parse_blacklist(json) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_blacklist'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'try_statement', 'children': ['8', '72']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '14']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '13', 'type': 'string', 'children': [], 'value': "'blacklist'"},{'id': '14', 'type': 'block', 'children': ['15', '30', '39', '51']},{'id': '15', 'type': 'if_statement', 'children': ['16', '18']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '18', 'type': 'block', 'children': ['19', '23']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '22', 'type': 'string', 'children': [], 'value': '"invalid json format. Blacklist entries cannot be null or empty"'},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '__encode'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bl'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_blacklist'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '54']},{'id': '52', 'type': 'not_operator', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'bl'},{'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': 'bl'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'MatchingBlacklist'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '71']},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_blacklist'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bl'},{'id': '72', 'type': 'except_clause', 'children': ['73', '77']},{'id': '73', 'type': 'as_pattern', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '75', 'type': 'as_pattern_target', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '77', 'type': 'block', 'children': ['78', '86']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': '"invalid json format. Attribute %s not found"'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '86', 'type': 'raise_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'msg'} | def __parse_blacklist(self, json):
try:
for entry in json['blacklist']:
if not entry:
msg = "invalid json format. Blacklist entries cannot be null or empty"
raise InvalidFormatError(cause=msg)
excluded = self.__encode(entry)
bl = self._blacklist.get(excluded, None)
if not bl:
bl = MatchingBlacklist(excluded=excluded)
self._blacklist[excluded] = bl
except KeyError as e:
msg = "invalid json format. Attribute %s not found" % e.args
raise InvalidFormatError(cause=msg) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_organizations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'try_statement', 'children': ['8', '115']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '14']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '13', 'type': 'string', 'children': [], 'value': "'organizations'"},{'id': '14', 'type': 'block', 'children': ['15', '24', '36', '57', '65']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '__encode'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'org'},{'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': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_organizations'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '39']},{'id': '37', 'type': 'not_operator', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '39', 'type': 'block', 'children': ['40', '49']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_organizations'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '63', 'type': 'string', 'children': [], 'value': "'organizations'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '68', 'type': 'block', 'children': ['69', '90', '106']},{'id': '69', 'type': 'if_statement', 'children': ['70', '78']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '77'], 'value': '!='},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '76', 'type': 'string', 'children': [], 'value': "'is_top'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '78', 'type': 'block', 'children': ['79', '83']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '82', 'type': 'string', 'children': [], 'value': '"invalid json format. \'is_top\' must have a bool value"'},{'id': '83', 'type': 'raise_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Domain'},{'id': '95', 'type': 'argument_list', 'children': ['96', '101']},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '100', 'type': 'string', 'children': [], 'value': "'domain'"},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '105', 'type': 'string', 'children': [], 'value': "'is_top'"},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '115', 'type': 'except_clause', 'children': ['116', '120']},{'id': '116', 'type': 'as_pattern', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '118', 'type': 'as_pattern_target', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '120', 'type': 'block', 'children': ['121', '129']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '%'},{'id': '125', 'type': 'string', 'children': [], 'value': '"invalid json format. Attribute %s not found"'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'InvalidFormatError'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cause'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'msg'} | def __parse_organizations(self, json):
try:
for organization in json['organizations']:
name = self.__encode(organization)
org = self._organizations.get(name, None)
if not org:
org = Organization(name=name)
self._organizations[name] = org
domains = json['organizations'][organization]
for domain in domains:
if type(domain['is_top']) != bool:
msg = "invalid json format. 'is_top' must have a bool value"
raise InvalidFormatError(cause=msg)
dom = Domain(domain=domain['domain'],
is_top_domain=domain['is_top'])
org.domains.append(dom)
except KeyError as e:
msg = "invalid json format. Attribute %s not found" % e.args
raise InvalidFormatError(cause=msg) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_blacklist'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '6', 'type': 'block', 'children': ['7', '13', '20', '24', '94']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': '"Loading blacklist..."'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'try_statement', 'children': ['29', '58', '72']},{'id': '29', 'type': 'block', 'children': ['30', '42', '54']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'add_to_matching_blacklist'},{'id': '35', 'type': 'argument_list', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'load_blacklist.tmpl'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'augmented_assignment', 'children': ['56', '57'], 'value': '+='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'except_clause', 'children': ['59', '63']},{'id': '59', 'type': 'as_pattern', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'raise_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '72', 'type': 'except_clause', 'children': ['73', '77']},{'id': '73', 'type': 'as_pattern', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'AlreadyExistsError'},{'id': '75', 'type': 'as_pattern_target', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '77', 'type': 'block', 'children': ['78', '87']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': '"%s. Not added."'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '%'},{'id': '101', 'type': 'string', 'children': [], 'value': '"%d/%d blacklist entries loaded"'},{'id': '102', 'type': 'tuple', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'blacklist'} | def import_blacklist(self, parser):
blacklist = parser.blacklist
self.log("Loading blacklist...")
n = 0
for entry in blacklist:
try:
api.add_to_matching_blacklist(self.db, entry.excluded)
self.display('load_blacklist.tmpl', entry=entry.excluded)
n += 1
except ValueError as e:
raise RuntimeError(str(e))
except AlreadyExistsError as e:
msg = "%s. Not added." % str(e)
self.warning(msg)
self.log("%d/%d blacklist entries loaded" % (n, len(blacklist))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_organizations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'organizations'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '19', 'type': 'block', 'children': ['20', '55']},{'id': '20', 'type': 'try_statement', 'children': ['21', '34', '48']},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'add_organization'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '34', 'type': 'except_clause', 'children': ['35', '39']},{'id': '35', 'type': 'as_pattern', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '37', 'type': 'as_pattern_target', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '48', 'type': 'except_clause', 'children': ['49', '53']},{'id': '49', 'type': 'as_pattern', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'AlreadyExistsError'},{'id': '51', 'type': 'as_pattern_target', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'pass_statement', 'children': []},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'domains'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'try_statement', 'children': ['62', '103', '119']},{'id': '62', 'type': 'block', 'children': ['63', '86']},{'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': 'api'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'add_domain'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72', '75', '78', '83']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'is_top_domain'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '98']},{'id': '92', 'type': 'string', 'children': [], 'value': "'load_domains.tmpl'"},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '103', 'type': 'except_clause', 'children': ['104', '110']},{'id': '104', 'type': 'as_pattern', 'children': ['105', '108']},{'id': '105', 'type': 'tuple', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'NotFoundError'},{'id': '108', 'type': 'as_pattern_target', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'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': 'e'},{'id': '119', 'type': 'except_clause', 'children': ['120', '124']},{'id': '120', 'type': 'as_pattern', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'AlreadyExistsError'},{'id': '122', 'type': 'as_pattern_target', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '124', 'type': 'block', 'children': ['125', '134']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'},{'id': '129', 'type': 'string', 'children': [], 'value': '"%s. Not updated."'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'msg'} | def import_organizations(self, parser, overwrite=False):
orgs = parser.organizations
for org in orgs:
try:
api.add_organization(self.db, org.name)
except ValueError as e:
raise RuntimeError(str(e))
except AlreadyExistsError as e:
pass
for dom in org.domains:
try:
api.add_domain(self.db, org.name, dom.domain,
is_top_domain=dom.is_top_domain,
overwrite=overwrite)
self.display('load_domains.tmpl', domain=dom.domain,
organization=org.name)
except (ValueError, NotFoundError) as e:
raise RuntimeError(str(e))
except AlreadyExistsError as e:
msg = "%s. Not updated." % str(e)
self.warning(msg) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_identities'},{'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': 'parser'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'match_new'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'no_strict_matching'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '78', '84', '117']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '28', 'type': 'block', 'children': ['29', '34']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'no_strict_matching'},{'id': '34', 'type': 'try_statement', 'children': ['35', '58']},{'id': '35', 'type': 'block', 'children': ['36', '47']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'create_identity_matcher'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'matching'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '58', 'type': 'except_clause', 'children': ['59', '63']},{'id': '59', 'type': 'as_pattern', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'MatcherNotSupportedError'},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '63', 'type': 'block', 'children': ['64', '74']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '84', 'type': 'try_statement', 'children': ['85', '97']},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '__load_unique_identities'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94', '95', '96']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'uidentities'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'match_new'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'reset'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '97', 'type': 'except_clause', 'children': ['98', '102']},{'id': '98', 'type': 'as_pattern', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'LoadError'},{'id': '100', 'type': 'as_pattern_target', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '102', 'type': 'block', 'children': ['103', '113']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '113', 'type': 'return_statement', 'children': ['114']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'CMD_SUCCESS'} | def import_identities(self, parser, matching=None, match_new=False,
no_strict_matching=False,
reset=False, verbose=False):
matcher = None
if matching:
strict = not no_strict_matching
try:
blacklist = api.blacklist(self.db)
matcher = create_identity_matcher(matching, blacklist, strict=strict)
except MatcherNotSupportedError as e:
self.error(str(e))
return e.code
uidentities = parser.identities
try:
self.__load_unique_identities(uidentities, matcher, match_new,
reset, verbose)
except LoadError as e:
self.error(str(e))
return e.code
return CMD_SUCCESS |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__create_profile_from_identities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '8', 'type': 'block', 'children': ['9', '12', '16', '20', '24', '28', '32', '115', '153', '163', '175']},{'id': '9', 'type': 'import_statement', 'children': ['10']},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'EMAIL_ADDRESS_REGEX'},{'id': '15', 'type': 'string', 'children': [], 'value': 'r"^(?P<email>[^\\s@]+@[^\\s@.]+\\.[^\\s@]+)$"'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'NAME_REGEX'},{'id': '19', 'type': 'string', 'children': [], 'value': 'r"^\\w+\\s\\w+"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '35', 'type': 'block', 'children': ['36', '65', '94']},{'id': '36', 'type': 'if_statement', 'children': ['37', '43']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '40'], 'value': 'and'},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'm'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'NAME_REGEX'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'if_statement', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'},{'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': 'name'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '65', 'type': 'if_statement', 'children': ['66', '72']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '69'], 'value': 'and'},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '72', 'type': 'block', 'children': ['73', '85']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'EMAIL_ADDRESS_REGEX'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '94', 'type': 'if_statement', 'children': ['95', '97']},{'id': '95', 'type': 'not_operator', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'if_statement', 'children': ['99', '108']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'and'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '107'], 'value': '!='},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '107', 'type': 'string', 'children': [], 'value': "'None'"},{'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': 'username'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '115', 'type': 'if_statement', 'children': ['116', '118']},{'id': '116', 'type': 'not_operator', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '121', '133', '147']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'subscript', 'children': ['126', '132']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'elif_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '139', 'type': 'subscript', 'children': ['140', '146']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '152', 'type': 'None', 'children': []},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '156', 'type': 'dictionary', 'children': ['157', '160']},{'id': '157', 'type': 'pair', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '160', 'type': 'pair', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'edit_profile'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172', '173']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '173', 'type': 'dictionary_splat', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'kw'},{'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': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '%'},{'id': '182', 'type': 'string', 'children': [], 'value': '"-- profile %s updated"'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'verbose'} | def __create_profile_from_identities(self, identities, uuid, verbose):
import re
EMAIL_ADDRESS_REGEX = r"^(?P<email>[^\s@]+@[^\s@.]+\.[^\s@]+)$"
NAME_REGEX = r"^\w+\s\w+"
name = None
email = None
username = None
for identity in identities:
if not name and identity.name:
m = re.match(NAME_REGEX, identity.name)
if m:
name = identity.name
if not email and identity.email:
m = re.match(EMAIL_ADDRESS_REGEX, identity.email)
if m:
email = identity.email
if not username:
if identity.username and identity.username != 'None':
username = identity.username
if not name:
if email:
name = email.split('@')[0]
elif username:
name = username.split('@')[0]
else:
name = None
kw = {'name': name,
'email': email}
api.edit_profile(self.db, uuid, **kw)
self.log("-- profile %s updated" % uuid, verbose) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_identities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'email_to_employer'},{'id': '7', 'type': 'block', 'children': ['8', '15', '22', '181']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '__parse_aliases_stream'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '__parse_email_to_employer_stream'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'email_to_employer'},{'id': '22', 'type': 'for_statement', 'children': ['23', '26', '33']},{'id': '23', 'type': 'pattern_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'email'},{'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': '__raw_aliases'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '46', '124', '139', '172']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'if_statement', 'children': ['47', '49']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '49', 'type': 'block', 'children': ['50', '59', '74', '107', '116']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70', '71']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'EMAIL_ADDRESS_REGEX'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'UNICODE'},{'id': '74', 'type': 'if_statement', 'children': ['75', '76', '91']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '82', 'type': 'argument_list', 'children': ['83', '86']},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '98', 'type': 'argument_list', 'children': ['99', '102']},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '123']},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '131', 'type': 'argument_list', 'children': ['132', '135', '136']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'EMAIL_ADDRESS_REGEX'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'UNICODE'},{'id': '139', 'type': 'if_statement', 'children': ['140', '141', '156']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '147', 'type': 'argument_list', 'children': ['148', '151']},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'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': 'identity'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '163', 'type': 'argument_list', 'children': ['164', '167']},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'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': 'uid'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '186']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '__raw_identities'},{'id': '186', 'type': 'block', 'children': ['187', '267', '275', '289', '293']},{'id': '187', 'type': 'if_statement', 'children': ['188', '193', '202', '225']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'in'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '202', 'type': 'elif_clause', 'children': ['203', '208']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'in'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': '__raw_aliases'},{'id': '208', 'type': 'block', 'children': ['209', '217']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'canonical'},{'id': '212', 'type': 'subscript', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '__raw_aliases'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '220', 'type': 'subscript', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'canonical'},{'id': '225', 'type': 'else_clause', 'children': ['226']},{'id': '226', 'type': 'block', 'children': ['227', '236', '250', '259']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'UniqueIdentity'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'Identity'},{'id': '241', 'type': 'argument_list', 'children': ['242', '245']},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '257']},{'id': '252', 'type': 'attribute', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'identities'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '266']},{'id': '261', 'type': 'subscript', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '264', 'type': 'identifier', 'children': [], 'value': '_identities'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'enrs'},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '273', 'type': 'identifier', 'children': [], 'value': '__raw_identities'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'enrs'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '283', 'type': 'lambda', 'children': ['284', '286']},{'id': '284', 'type': 'lambda_parameters', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '288', 'type': 'integer', 'children': [], 'value': '1'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'start_date'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '293', 'type': 'for_statement', 'children': ['294', '295', '296']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'enrs'},{'id': '296', 'type': 'block', 'children': ['297', '303', '315', '336', '342', '357', '366']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '302', 'type': 'integer', 'children': [], 'value': '0'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '306', 'type': 'call', 'children': ['307', '312']},{'id': '307', 'type': 'attribute', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '310', 'type': 'identifier', 'children': [], 'value': '_organizations'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '314', 'type': 'None', 'children': []},{'id': '315', 'type': 'if_statement', 'children': ['316', '318']},{'id': '316', 'type': 'not_operator', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '318', 'type': 'block', 'children': ['319', '328']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'Organization'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '335']},{'id': '330', 'type': 'subscript', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_organizations'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'end_date'},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '341', 'type': 'integer', 'children': [], 'value': '1'},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'enrollment'},{'id': '345', 'type': 'call', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'Enrollment'},{'id': '347', 'type': 'argument_list', 'children': ['348', '351', '354']},{'id': '348', 'type': 'keyword_argument', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'start_date'},{'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'end_date'},{'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'organization'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '364']},{'id': '359', 'type': 'attribute', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'enrollments'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'enrollment'},{'id': '366', 'type': 'if_statement', 'children': ['367', '370']},{'id': '367', 'type': 'comparison_operator', 'children': ['368', '369'], 'value': '!='},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'end_date'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '370', 'type': 'block', 'children': ['371']},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'assignment', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'start_date'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'end_date'} | def __parse_identities(self, aliases, email_to_employer):
self.__parse_aliases_stream(aliases)
self.__parse_email_to_employer_stream(email_to_employer)
for alias, email in self.__raw_aliases.items():
uid = self._identities.get(email, None)
if not uid:
uid = UniqueIdentity(uuid=email)
e = re.match(self.EMAIL_ADDRESS_REGEX, email, re.UNICODE)
if e:
identity = Identity(email=email, source=self.source)
else:
identity = Identity(username=email, source=self.source)
uid.identities.append(identity)
self._identities[email] = uid
e = re.match(self.EMAIL_ADDRESS_REGEX, alias, re.UNICODE)
if e:
identity = Identity(email=alias, source=self.source)
else:
identity = Identity(username=alias, source=self.source)
uid.identities.append(identity)
for email in self.__raw_identities:
if email in self._identities:
uid = self._identities[email]
elif email in self.__raw_aliases:
canonical = self.__raw_aliases[email]
uid = self._identities[canonical]
else:
uid = UniqueIdentity(uuid=email)
identity = Identity(email=email, source=self.source)
uid.identities.append(identity)
self._identities[email] = uid
enrs = self.__raw_identities[email]
enrs.sort(key=lambda r: r[1])
start_date = MIN_PERIOD_DATE
for rol in enrs:
name = rol[0]
org = self._organizations.get(name, None)
if not org:
org = Organization(name=name)
self._organizations[name] = org
end_date = rol[1]
enrollment = Enrollment(start=start_date, end=end_date,
organization=org)
uid.enrollments.append(enrollment)
if end_date != MAX_PERIOD_DATE:
start_date = end_date |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'initialize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'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': 'reuse'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '18', '26', '34', '42', '58', '158']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '13', 'type': 'subscript', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_kwargs'},{'id': '17', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_kwargs'},{'id': '25', 'type': 'string', 'children': [], 'value': "'password'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'host'},{'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': '_kwargs'},{'id': '33', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_kwargs'},{'id': '41', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'},{'id': '44', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '46', 'type': 'block', 'children': ['47', '56']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'},{'id': '54', 'type': 'string', 'children': [], 'value': '"dabase name \'%s\' cannot contain \'-\' characters"'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'CODE_VALUE_ERROR'},{'id': '58', 'type': 'try_statement', 'children': ['59', '89', '111', '129']},{'id': '59', 'type': 'block', 'children': ['60', '71', '82']},{'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': 'Database'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68', '69', '70']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'Database'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '80', '81']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'port'},{'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': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '__load_countries'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '89', 'type': 'except_clause', 'children': ['90', '94']},{'id': '90', 'type': 'as_pattern', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'DatabaseExists'},{'id': '92', 'type': 'as_pattern_target', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '98']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'reuse'},{'id': '98', 'type': 'block', 'children': ['99', '109']},{'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': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'CODE_DATABASE_EXISTS'},{'id': '111', 'type': 'except_clause', 'children': ['112', '116']},{'id': '112', 'type': 'as_pattern', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'DatabaseError'},{'id': '114', 'type': 'as_pattern_target', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '116', 'type': 'block', 'children': ['117', '127']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'CODE_DATABASE_ERROR'},{'id': '129', 'type': 'except_clause', 'children': ['130', '134']},{'id': '130', 'type': 'as_pattern', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'LoadError'},{'id': '132', 'type': 'as_pattern_target', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '134', 'type': 'block', 'children': ['135', '146', '156']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'Database'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142', '143', '144', '145']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'port'},{'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': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'CODE_LOAD_ERROR'},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'CMD_SUCCESS'} | def initialize(self, name, reuse=False):
user = self._kwargs['user']
password = self._kwargs['password']
host = self._kwargs['host']
port = self._kwargs['port']
if '-' in name:
self.error("dabase name '%s' cannot contain '-' characters" % name)
return CODE_VALUE_ERROR
try:
Database.create(user, password, name, host, port)
db = Database(user, password, name, host, port)
self.__load_countries(db)
except DatabaseExists as e:
if not reuse:
self.error(str(e))
return CODE_DATABASE_EXISTS
except DatabaseError as e:
self.error(str(e))
return CODE_DATABASE_ERROR
except LoadError as e:
Database.drop(user, password, name, host, port)
self.error(str(e))
return CODE_LOAD_ERROR
return CMD_SUCCESS |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_date_ranges'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '5', 'type': 'block', 'children': ['6', '11', '25', '34', '153']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted_dates'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'list_comprehension', 'children': ['18', '22']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dates'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted_dates'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'for_statement', 'children': ['35', '38', '39']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted_dates'},{'id': '39', 'type': 'block', 'children': ['40', '59', '78']},{'id': '40', 'type': 'if_statement', 'children': ['41', '48']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '45'], 'value': 'or'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '<'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '>'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '%'},{'id': '54', 'type': 'string', 'children': [], 'value': '"start date %s is out of bounds"'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '59', 'type': 'if_statement', 'children': ['60', '67']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '64'], 'value': 'or'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '<'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '>'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'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': 'ValueError'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'},{'id': '73', 'type': 'string', 'children': [], 'value': '"end date %s is out of bounds"'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '78', 'type': 'if_statement', 'children': ['79', '84', '133']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '<='},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'block', 'children': ['85', '98']},{'id': '85', 'type': 'if_statement', 'children': ['86', '91']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'MIN_PERIOD_DATE'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '98', 'type': 'if_statement', 'children': ['99', '106', '119']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'MAX_PERIOD_DATE'},{'id': '101', 'type': 'tuple', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'saved'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '128', 'type': 'argument_list', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135', '141', '147']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'yield', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'saved'},{'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': 'saved'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'saved'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'yield', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'saved'} | def merge_date_ranges(dates):
if not dates:
return
sorted_dates = sorted([sorted(t) for t in dates])
saved = list(sorted_dates[0])
for st, en in sorted_dates:
if st < MIN_PERIOD_DATE or st > MAX_PERIOD_DATE:
raise ValueError("start date %s is out of bounds" % str(st))
if en < MIN_PERIOD_DATE or en > MAX_PERIOD_DATE:
raise ValueError("end date %s is out of bounds" % str(en))
if st <= saved[1]:
if saved[0] == MIN_PERIOD_DATE:
saved[0] = st
if MAX_PERIOD_DATE in (en, saved[1]):
saved[1] = min(saved[1], en)
else:
saved[1] = max(saved[1], en)
else:
yield tuple(saved)
saved[0] = st
saved[1] = en
yield tuple(saved) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'uuid'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '25', '35', '49', '81', '98', '106']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"source cannot be None"'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '28', 'type': 'string', 'children': [], 'value': "''"},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': '"source cannot be an empty string"'},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'or'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '"identity data cannot be None or empty"'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '52', 'type': 'call', 'children': ['53', '80']},{'id': '53', 'type': 'attribute', 'children': ['54', '79']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "':'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'tuple', 'children': ['60', '64', '68', '75']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'email'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'unaccent'},{'id': '74', 'type': 'True', 'children': []},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'UTF-8'"},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '97', 'type': 'string', 'children': [], 'value': '"surrogateescape"'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'uuid_'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'uuid_'} | def uuid(source, email=None, name=None, username=None):
if source is None:
raise ValueError("source cannot be None")
if source == '':
raise ValueError("source cannot be an empty string")
if not (email or name or username):
raise ValueError("identity data cannot be None or empty")
s = ':'.join((to_unicode(source),
to_unicode(email),
to_unicode(name, unaccent=True),
to_unicode(username))).lower()
sha1 = hashlib.sha1(s.encode('UTF-8', errors="surrogateescape"))
uuid_ = sha1.hexdigest()
return uuid_ |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'call'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '11', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'list_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '11', 'type': 'typed_default_parameter', 'children': ['12', '13', '15']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'dictionary_splat_pattern', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '18', 'type': 'block', 'children': ['19', '32', '40', '53', '64', '72', '162', '173']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'rpc_request'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '30']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '28', 'type': 'list_splat', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '30', 'type': 'dictionary_splat', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_log'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Sending request: %s"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '40', 'type': 'expression_statement', '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': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_socket'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'send_multipart'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '[to_msgpack(request)]'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'to_msgpack'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'while_statement', 'children': ['73', '74']},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'block', 'children': ['75', '99', '116', '127', '134', '142']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '78', 'type': 'conditional_expression', 'children': ['79', '95', '98'], 'value': 'if'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '81', 'type': 'argument_list', 'children': ['82', '94']},{'id': '82', 'type': 'binary_operator', 'children': ['83', '93'], 'value': '*'},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '88'], 'value': '-'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '+'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'rpc_timeout'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'if_statement', 'children': ['100', '110']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '109'], 'value': '=='},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_socket'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'poll'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'TimeoutError'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': 'f"Timeout on client {self.endpoint}, method name {method_name}, class info: {self}"'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '120']},{'id': '118', 'type': 'pattern_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'raw_reply'},{'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': '_socket'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'recv_multipart'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'from_msgpack'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'raw_reply'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': '_log'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': '"Received reply: %s"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '142', 'type': 'if_statement', 'children': ['143', '150', '152']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '=='},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'break_statement', 'children': []},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_log'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "'Discarding reply: %s'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '162', 'type': 'for_statement', 'children': ['163', '164', '167']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'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': 'warn'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': 'f"{warning.kind}: {warning.body}"'},{'id': '173', 'type': 'if_statement', 'children': ['174', '179', '189']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'RPCError'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'raise_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'RPCError'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'reply'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'result'} | def call(self, method_name: str, *args, rpc_timeout: float = None, **kwargs):
request = utils.rpc_request(method_name, *args, **kwargs)
_log.debug("Sending request: %s", request)
self._socket.send_multipart([to_msgpack(request)])
if rpc_timeout is None:
rpc_timeout = self.rpc_timeout
start_time = time.time()
while True:
timeout = max((start_time + rpc_timeout - time.time()) * 1000, 0) if rpc_timeout is not None else None
if self._socket.poll(timeout) == 0:
raise TimeoutError(f"Timeout on client {self.endpoint}, method name {method_name}, class info: {self}")
raw_reply, = self._socket.recv_multipart()
reply = from_msgpack(raw_reply)
_log.debug("Received reply: %s", reply)
if reply.id == request.id:
break
else:
_log.debug('Discarding reply: %s', reply)
for warning in reply.warnings:
warn(f"{warning.kind}: {warning.body}")
if isinstance(reply, RPCError):
raise utils.RPCError(reply.error)
else:
return reply.result |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'init_process_dut'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'block', 'children': ['9', '311', '320']},{'id': '9', 'type': 'if_statement', 'children': ['10', '17', '97']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '14'], 'value': 'and'},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'},{'id': '12', 'type': 'string', 'children': [], 'value': '"subtype"'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '16', 'type': 'string', 'children': [], 'value': '"subtype"'},{'id': '17', 'type': 'block', 'children': ['18', '50', '54', '65', '74', '91']},{'id': '18', 'type': 'if_statement', 'children': ['19', '24']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '!='},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '22', 'type': 'string', 'children': [], 'value': '"subtype"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"console"'},{'id': '24', 'type': 'block', 'children': ['25', '29', '45']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '28', 'type': 'string', 'children': [], 'value': '"Unrecognized process subtype: {}"'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '44', 'type': 'string', 'children': [], 'value': '"subtype"'},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ResourceInitError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '"Unrecognized process subtype: {}"'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'string', 'children': [], 'value': '"application"'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'conf'},{'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': 'config'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '64', 'type': 'string', 'children': [], 'value': '"application"'},{'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': 'contextlist'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': '"Starting a remote console"'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'DutConsole'},{'id': '79', 'type': 'argument_list', 'children': ['80', '85', '88']},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'},{'id': '83', 'type': 'string', 'children': [], 'value': '"D%d"'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99', '107', '113', '123', '133', '144', '161', '167', '173', '200', '224', '252', '276', '287', '299']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '102', 'type': 'subscript', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '105', 'type': 'string', 'children': [], 'value': '"application"'},{'id': '106', 'type': 'string', 'children': [], 'value': "'bin'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'app_config'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '112', 'type': 'string', 'children': [], 'value': '"application"'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'init_cli_cmds'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'app_config'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': '"init_cli_cmds"'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'post_cli_cmds'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'app_config'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': '"post_cli_cmds"'},{'id': '132', 'type': 'None', 'children': []},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'},{'id': '142', 'type': 'string', 'children': [], 'value': '"Starting process \'%s\'"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'DutProcess'},{'id': '149', 'type': 'argument_list', 'children': ['150', '155', '158']},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '%'},{'id': '153', 'type': 'string', 'children': [], 'value': '"D%d"'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'binary'},{'id': '173', 'type': 'if_statement', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'valgrind'},{'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': 'dut'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'use_valgrind'},{'id': '183', 'type': 'argument_list', 'children': ['184', '187', '191', '194', '197']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'valgrind_tool'},{'id': '187', 'type': 'not_operator', 'children': ['188']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'valgrind_text'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'valgrind_console'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'valgrind_track_origins'},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'valgrind_extra_params'},{'id': '200', 'type': 'if_statement', 'children': ['201', '206']},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '205'], 'value': '=='},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'gdb'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '206', 'type': 'block', 'children': ['207', '213']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'use_gdb'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'binary_operator', 'children': ['222', '223'], 'value': '%'},{'id': '222', 'type': 'string', 'children': [], 'value': '"GDB is activated for node %i"'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '224', 'type': 'if_statement', 'children': ['225', '230']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '229'], 'value': '=='},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'gdbs'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '230', 'type': 'block', 'children': ['231', '241']},{'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': 'dut'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'use_gdbs'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238']},{'id': '237', 'type': 'True', 'children': []},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'gdbs_port'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '248']},{'id': '243', 'type': 'attribute', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '%'},{'id': '250', 'type': 'string', 'children': [], 'value': '"GDBserver is activated for node %i"'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '252', 'type': 'if_statement', 'children': ['253', '258']},{'id': '253', 'type': 'comparison_operator', 'children': ['254', '257'], 'value': '=='},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'vgdb'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '258', 'type': 'block', 'children': ['259', '265']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'use_vgdb'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '272']},{'id': '267', 'type': 'attribute', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '%'},{'id': '274', 'type': 'string', 'children': [], 'value': '"VGDB is activated for node %i"'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '276', 'type': 'if_statement', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'nobuf'},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'no_std_buf'},{'id': '286', 'type': 'argument_list', 'children': []},{'id': '287', 'type': 'if_statement', 'children': ['288', '291']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': 'is'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'init_cli_cmds'},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'set_init_cli_cmds'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'init_cli_cmds'},{'id': '299', 'type': 'if_statement', 'children': ['300', '303']},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'is'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'post_cli_cmds'},{'id': '302', 'type': 'None', 'children': []},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'set_post_cli_cmds'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'post_cli_cmds'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '318']},{'id': '313', 'type': 'attribute', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'duts'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '327']},{'id': '322', 'type': 'attribute', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'contextlist'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'dutinformations'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'dut'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'get_info'},{'id': '332', 'type': 'argument_list', 'children': []} | def init_process_dut(contextlist, conf, index, args):
if "subtype" in conf and conf["subtype"]:
if conf["subtype"] != "console":
msg = "Unrecognized process subtype: {}"
contextlist.logger.error(msg.format(conf["subtype"]))
raise ResourceInitError("Unrecognized process subtype: {}")
config = None
if "application" in conf:
config = conf["application"]
contextlist.logger.debug("Starting a remote console")
dut = DutConsole(name="D%d" % index, conf=config, params=args)
dut.index = index
else:
binary = conf["application"]['bin']
app_config = conf["application"]
init_cli_cmds = app_config.get("init_cli_cmds", None)
post_cli_cmds = app_config.get("post_cli_cmds", None)
contextlist.logger.debug("Starting process '%s'" % binary)
dut = DutProcess(name="D%d" % index, config=conf, params=args)
dut.index = index
dut.command = binary
if args.valgrind:
dut.use_valgrind(args.valgrind_tool,
not args.valgrind_text,
args.valgrind_console,
args.valgrind_track_origins,
args.valgrind_extra_params)
if args.gdb == index:
dut.use_gdb()
contextlist.logger.info("GDB is activated for node %i" % index)
if args.gdbs == index:
dut.use_gdbs(True, args.gdbs_port)
contextlist.logger.info("GDBserver is activated for node %i" % index)
if args.vgdb == index:
dut.use_vgdb()
contextlist.logger.info("VGDB is activated for node %i" % index)
if args.nobuf:
dut.no_std_buf()
if init_cli_cmds is not None:
dut.set_init_cli_cmds(init_cli_cmds)
if post_cli_cmds is not None:
dut.set_post_cli_cmds(post_cli_cmds)
contextlist.duts.append(dut)
contextlist.dutinformations.append(dut.get_info()) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'allocate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dut_configuration_list'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '18', '31', '81', '116', '122', '126', '173', '181', '189', '197']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dut_configuration_list'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_dut_configuration'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '25']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'AllocationError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '"Invalid dut configuration format!"'},{'id': '31', 'type': 'if_statement', 'children': ['32', '50']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '34', 'type': 'argument_list', 'children': ['35', '49']},{'id': '35', 'type': 'generator_expression', 'children': ['36', '37', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '40', 'type': 'if_clause', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '48'], 'value': '=='},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '48', 'type': 'string', 'children': [], 'value': '"hardware"'},{'id': '49', 'type': 'False', 'children': []},{'id': '50', 'type': 'block', 'children': ['51', '63']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_available_devices'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'DutDetection'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_available_devices'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '75']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '71'], 'value': '<'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'},{'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': '_available_devices'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': '"Required amount of devices not available."'},{'id': '81', 'type': 'try_statement', 'children': ['82', '112']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dut_config'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '86', 'type': 'block', 'children': ['87', '105']},{'id': '87', 'type': 'if_statement', 'children': ['88', '99']},{'id': '88', 'type': 'not_operator', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'can_allocate'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dut_config'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_requirements'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"Resource type is not supported"'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_allocate'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dut_config'},{'id': '112', 'type': 'except_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'raise_statement', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'alloc_list'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'AllocationContextList'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'res_id'},{'id': '125', 'type': 'None', 'children': []},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dut_config_list'},{'id': '129', 'type': 'block', 'children': ['130', '154', '166']},{'id': '130', 'type': 'if_statement', 'children': ['131', '139']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '138'], 'value': '=='},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '138', 'type': 'string', 'children': [], 'value': '"mbed"'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'res_id'},{'id': '143', 'type': 'call', 'children': ['144', '152']},{'id': '144', 'type': 'attribute', 'children': ['145', '151']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': '"allocated"'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': '"target_id"'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'AllocationContext'},{'id': '159', 'type': 'argument_list', 'children': ['160', '163']},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'resource_id'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'res_id'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'alloc_data'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'conf'},{'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': 'alloc_list'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'context'},{'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': 'alloc_list'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'set_dut_init_function'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': '"serial"'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'init_generic_serial_dut'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'alloc_list'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'set_dut_init_function'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': '"process"'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'init_process_dut'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'alloc_list'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'set_dut_init_function'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': '"mbed"'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'init_mbed_dut'},{'id': '197', 'type': 'return_statement', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'alloc_list'} | def allocate(self, dut_configuration_list, args=None):
dut_config_list = dut_configuration_list.get_dut_configuration()
if not isinstance(dut_config_list, list):
raise AllocationError("Invalid dut configuration format!")
if next((item for item in dut_config_list if item.get("type") == "hardware"), False):
self._available_devices = DutDetection().get_available_devices()
if len(self._available_devices) < len(dut_config_list):
raise AllocationError("Required amount of devices not available.")
try:
for dut_config in dut_config_list:
if not self.can_allocate(dut_config.get_requirements()):
raise AllocationError("Resource type is not supported")
self._allocate(dut_config)
except AllocationError:
raise
alloc_list = AllocationContextList()
res_id = None
for conf in dut_config_list:
if conf.get("type") == "mbed":
res_id = conf.get("allocated").get("target_id")
context = AllocationContext(resource_id=res_id, alloc_data=conf)
alloc_list.append(context)
alloc_list.set_dut_init_function("serial", init_generic_serial_dut)
alloc_list.set_dut_init_function("process", init_process_dut)
alloc_list.set_dut_init_function("mbed", init_mbed_dut)
return alloc_list |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_allocate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '6', 'type': 'block', 'children': ['7', '22', '271']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '=='},{'id': '9', 'type': 'subscript', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '11', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '12', 'type': 'string', 'children': [], 'value': '"hardware"'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '21', 'type': 'string', 'children': [], 'value': '"mbed"'},{'id': '22', 'type': 'if_statement', 'children': ['23', '28', '214']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '26', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '27', 'type': 'string', 'children': [], 'value': '"mbed"'},{'id': '28', 'type': 'block', 'children': ['29', '40', '48', '59', '70', '83', '98', '209']},{'id': '29', 'type': 'if_statement', 'children': ['30', '34']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_available_devices'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': '"No available devices to allocate from"'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_requirements'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'platforms'},{'id': '51', 'type': 'conditional_expression', 'children': ['52', '53', '56'], 'value': 'if'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'not'},{'id': '54', 'type': 'string', 'children': [], 'value': "'allowed_platforms'"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '58', 'type': 'string', 'children': [], 'value': "'allowed_platforms'"},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '62', 'type': 'conditional_expression', 'children': ['63', '64', '67'], 'value': 'if'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'},{'id': '65', 'type': 'string', 'children': [], 'value': "'platform_name'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '69', 'type': 'string', 'children': [], 'value': '"platform_name"'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '75'], 'value': 'and'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'platforms'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'platforms'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'and'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'platforms'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'not'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'platforms'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'raise_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': '"Platform name not in allowed platforms."'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '103']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_available_devices'},{'id': '103', 'type': 'block', 'children': ['104', '132', '154']},{'id': '104', 'type': 'if_statement', 'children': ['105', '112']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '107'], 'value': 'and'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '!='},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '110', 'type': 'string', 'children': [], 'value': '"platform_name"'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '112', 'type': 'block', 'children': ['113', '131']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '120', 'type': 'argument_list', 'children': ['121', '124', '127', '128']},{'id': '121', 'type': 'concatenated_string', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': '"Skipping device %s because of mismatching platform. "'},{'id': '123', 'type': 'string', 'children': [], 'value': '"Required %s but device was %s"'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '126', 'type': 'string', 'children': [], 'value': "'target_id'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'platform_name'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '130', 'type': 'string', 'children': [], 'value': "'platform_name'"},{'id': '131', 'type': 'continue_statement', 'children': []},{'id': '132', 'type': 'if_statement', 'children': ['133', '138']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '=='},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '136', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'allocated'"},{'id': '138', 'type': 'block', 'children': ['139', '153']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '146', 'type': 'argument_list', 'children': ['147', '150']},{'id': '147', 'type': 'concatenated_string', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"Skipping device %s because it was "'},{'id': '149', 'type': 'string', 'children': [], 'value': '"already allocated"'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '152', 'type': 'string', 'children': [], 'value': "'target_id'"},{'id': '153', 'type': 'continue_statement', 'children': []},{'id': '154', 'type': 'if_statement', 'children': ['155', '163', '190']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'DutDetection'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'is_port_usable'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '162', 'type': 'string', 'children': [], 'value': "'serial_port'"},{'id': '163', 'type': 'block', 'children': ['164', '170', '176', '188']},{'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': 'dev'},{'id': '168', 'type': 'string', 'children': [], 'value': "'state'"},{'id': '169', 'type': 'string', 'children': [], 'value': '"allocated"'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '174', 'type': 'string', 'children': [], 'value': "'allocated'"},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '183']},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'string', 'children': [], 'value': '"Allocated device %s"'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '187', 'type': 'string', 'children': [], 'value': "'target_id'"},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'True', 'children': []},{'id': '190', 'type': 'else_clause', 'children': ['191']},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '199']},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '199', 'type': 'argument_list', 'children': ['200', '203', '206']},{'id': '200', 'type': 'concatenated_string', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '"Could not open serial port (%s) of "'},{'id': '202', 'type': 'string', 'children': [], 'value': '"allocated device %s"'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '205', 'type': 'string', 'children': [], 'value': "'serial_port'"},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'dev'},{'id': '208', 'type': 'string', 'children': [], 'value': "'target_id'"},{'id': '209', 'type': 'raise_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'string', 'children': [], 'value': '"No suitable local device available"'},{'id': '214', 'type': 'elif_clause', 'children': ['215', '220']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '219'], 'value': '=='},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '218', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '219', 'type': 'string', 'children': [], 'value': '"serial"'},{'id': '220', 'type': 'block', 'children': ['221', '229', '248']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'dut_configuration'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get_requirements'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'if_statement', 'children': ['230', '237']},{'id': '230', 'type': 'not_operator', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'string', 'children': [], 'value': '"serial_port"'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'raise_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'string', 'children': [], 'value': '"Serial port not defined for requirement {}"'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '248', 'type': 'if_statement', 'children': ['249', '258']},{'id': '249', 'type': 'not_operator', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'DutDetection'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'is_port_usable'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '257', 'type': 'string', 'children': [], 'value': "'serial_port'"},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'raise_statement', 'children': ['260']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'AllocationError'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': '"Serial port {} not usable"'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'dut_reqs'},{'id': '270', 'type': 'string', 'children': [], 'value': "'serial_port'"},{'id': '271', 'type': 'return_statement', 'children': ['272']},{'id': '272', 'type': 'True', 'children': []} | def _allocate(self, dut_configuration):
if dut_configuration["type"] == "hardware":
dut_configuration.set("type", "mbed")
if dut_configuration["type"] == "mbed":
if not self._available_devices:
raise AllocationError("No available devices to allocate from")
dut_reqs = dut_configuration.get_requirements()
platforms = None if 'allowed_platforms' not in dut_reqs else dut_reqs[
'allowed_platforms']
platform_name = None if 'platform_name' not in dut_reqs else dut_reqs[
"platform_name"]
if platform_name is None and platforms:
platform_name = platforms[0]
if platform_name and platforms:
if platform_name not in platforms:
raise AllocationError("Platform name not in allowed platforms.")
for dev in self._available_devices:
if platform_name and dev["platform_name"] != platform_name:
self.logger.debug("Skipping device %s because of mismatching platform. "
"Required %s but device was %s", dev['target_id'],
platform_name, dev['platform_name'])
continue
if dev['state'] == 'allocated':
self.logger.debug("Skipping device %s because it was "
"already allocated", dev['target_id'])
continue
if DutDetection.is_port_usable(dev['serial_port']):
dev['state'] = "allocated"
dut_reqs['allocated'] = dev
self.logger.info("Allocated device %s", dev['target_id'])
return True
else:
self.logger.info("Could not open serial port (%s) of "
"allocated device %s", dev['serial_port'], dev['target_id'])
raise AllocationError("No suitable local device available")
elif dut_configuration["type"] == "serial":
dut_reqs = dut_configuration.get_requirements()
if not dut_reqs.get("serial_port"):
raise AllocationError("Serial port not defined for requirement {}".format(dut_reqs))
if not DutDetection.is_port_usable(dut_reqs['serial_port']):
raise AllocationError("Serial port {} not usable".format(dut_reqs['serial_port']))
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__generate'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '5', 'type': 'block', 'children': ['6', '19', '23', '27', '31', '35', '96', '312']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '12']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Doc'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tagtext'},{'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': 'count'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fails'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'skips'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '38', 'type': 'block', 'children': ['39', '56', '60']},{'id': '39', 'type': 'if_statement', 'children': ['40', '47']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '46'], 'value': 'is'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'False', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '54']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': '>'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'continue_statement', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'augmented_assignment', 'children': ['58', '59'], 'value': '+='},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'if_statement', 'children': ['61', '66', '68', '79', '90']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'continue_statement', 'children': []},{'id': '68', 'type': 'elif_clause', 'children': ['69', '74']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'skipped'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'augmented_assignment', 'children': ['77', '78'], 'value': '+='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'skips'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'elif_clause', 'children': ['80', '85']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'was_inconclusive'},{'id': '84', 'type': 'argument_list', 'children': []},{'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': 'errors'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'fails'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'with_statement', 'children': ['97', '127']},{'id': '97', 'type': 'with_clause', 'children': ['98']},{'id': '98', 'type': 'with_item', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '109', '115', '121']},{'id': '102', 'type': 'string', 'children': [], 'value': "'testsuite'"},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tests'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'failures'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fails'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'skipped'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'skips'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '131', 'type': 'block', 'children': ['132', '148', '156', '164', '175', '183']},{'id': '132', 'type': 'if_statement', 'children': ['133', '146']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '141'], 'value': 'and'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '140'], 'value': 'is'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'False', 'children': []},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': '>'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'retries_left'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'continue_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'get_tc_name'},{'id': '155', 'type': 'argument_list', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get_dut_models'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'if_statement', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '170', 'type': 'binary_operator', 'children': ['171', '174'], 'value': '+'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '173', 'type': 'string', 'children': [], 'value': '"."'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'get_toolchain'},{'id': '182', 'type': 'argument_list', 'children': []},{'id': '183', 'type': 'with_statement', 'children': ['184', '206']},{'id': '184', 'type': 'with_clause', 'children': ['185']},{'id': '185', 'type': 'with_item', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190', '193', '196']},{'id': '189', 'type': 'string', 'children': [], 'value': "'testcase'"},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'classname'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'get_duration'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '205', 'type': 'True', 'children': []},{'id': '206', 'type': 'block', 'children': ['207', '227']},{'id': '207', 'type': 'if_statement', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'with_statement', 'children': ['213', '219']},{'id': '213', 'type': 'with_clause', 'children': ['214']},{'id': '214', 'type': 'with_item', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'string', 'children': [], 'value': "'system-out'"},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '227', 'type': 'if_statement', 'children': ['228', '233', '235', '257', '287']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'passed'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'continue_statement', 'children': []},{'id': '235', 'type': 'elif_clause', 'children': ['236', '241']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'skipped'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'with_statement', 'children': ['243', '249']},{'id': '243', 'type': 'with_clause', 'children': ['244']},{'id': '244', 'type': 'with_item', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'string', 'children': [], 'value': "'skipped'"},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'skip_reason'},{'id': '257', 'type': 'elif_clause', 'children': ['258', '263']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'was_inconclusive'},{'id': '262', 'type': 'argument_list', 'children': []},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'with_statement', 'children': ['265', '279']},{'id': '265', 'type': 'with_clause', 'children': ['266']},{'id': '266', 'type': 'with_item', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'string', 'children': [], 'value': "'error'"},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'hex_escape_str'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'fail_reason'},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '287', 'type': 'else_clause', 'children': ['288']},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'with_statement', 'children': ['290', '304']},{'id': '290', 'type': 'with_clause', 'children': ['291']},{'id': '291', 'type': 'with_item', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296']},{'id': '295', 'type': 'string', 'children': [], 'value': "'failure'"},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'hex_escape_str'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'fail_reason'},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '312', 'type': 'return_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '315', 'type': 'argument_list', 'children': ['316', '321']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '320', 'type': 'argument_list', 'children': []},{'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'indentation'},{'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '*'},{'id': '324', 'type': 'string', 'children': [], 'value': "' '"},{'id': '325', 'type': 'integer', 'children': [], 'value': '4'} | def __generate(results):
doc, tag, text = Doc().tagtext()
count = 0
fails = 0
errors = 0
skips = 0
for result in results:
if result.passed() is False:
if result.retries_left > 0:
continue
count += 1
if result.passed():
continue
elif result.skipped():
skips += 1
elif result.was_inconclusive():
errors += 1
else:
fails += 1
with tag('testsuite',
tests=str(count),
failures=str(fails),
errors=str(errors),
skipped=str(skips)):
for result in results:
if result.passed() is False and result.retries_left > 0:
continue
class_name = result.get_tc_name()
models = result.get_dut_models()
if models:
class_name = class_name + "." + models
name = result.get_toolchain()
with tag('testcase', classname=class_name, name=name,
time=result.get_duration(seconds=True)):
if result.stdout:
with tag('system-out'):
text(result.stdout)
if result.passed():
continue
elif result.skipped():
with tag('skipped'):
text(result.skip_reason)
elif result.was_inconclusive():
with tag('error', message=hex_escape_str(result.fail_reason)):
text(result.stderr)
else:
with tag('failure', message=hex_escape_str(result.fail_reason)):
text(result.stderr)
return indent(
doc.getvalue(),
indentation=' '*4
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'init_base_logging'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '6', 'type': 'string', 'children': [], 'value': '"./log"'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '9', 'type': 'integer', 'children': [], 'value': '0'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'no_file'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'truncate'},{'id': '21', 'type': 'True', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'config_location'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '28', '30', '32', '34', '36', '38', '87', '115', '124', '130', '139', '147', '175', '312', '316', '320', '376', '426', '433', '437', '449']},{'id': '26', 'type': 'global_statement', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'LOGPATHDIR'},{'id': '28', 'type': 'global_statement', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'STANDALONE_LOGGING'},{'id': '30', 'type': 'global_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'TRUNCATE_LOG'},{'id': '32', 'type': 'global_statement', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'COLOR_ON'},{'id': '34', 'type': 'global_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'SILENT_ON'},{'id': '36', 'type': 'global_statement', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_LEVEL'},{'id': '38', 'type': 'if_statement', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'config_location'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'try_statement', 'children': ['42', '48', '65']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_read_config'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'config_location'},{'id': '48', 'type': 'except_clause', 'children': ['49', '53']},{'id': '49', 'type': 'as_pattern', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '51', 'type': 'as_pattern_target', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': '"Unable to read from configuration file {}: {}"'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'config_location'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '65', 'type': 'except_clause', 'children': ['66', '72']},{'id': '66', 'type': 'as_pattern', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'jsonschema'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'SchemaError'},{'id': '70', 'type': 'as_pattern_target', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'jsonschema'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'SchemaError'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'concatenated_string', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"Logging configuration schema "'},{'id': '83', 'type': 'string', 'children': [], 'value': '"file malformed: {}"'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'LOGPATHDIR'},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '98', 'type': 'call', 'children': ['99', '113']},{'id': '99', 'type': 'attribute', 'children': ['100', '112']},{'id': '100', 'type': 'call', 'children': ['101', '110']},{'id': '101', 'type': 'attribute', 'children': ['102', '109']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d_%H%M%S.%f"'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': '"0"'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '"icetea"'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'propagate'},{'id': '129', 'type': 'False', 'children': []},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'StreamHandler'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'BenchFormatter'},{'id': '152', 'type': 'argument_list', 'children': ['153', '164']},{'id': '153', 'type': 'call', 'children': ['154', '162']},{'id': '154', 'type': 'attribute', 'children': ['155', '161']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '"format"'},{'id': '164', 'type': 'call', 'children': ['165', '173']},{'id': '165', 'type': 'attribute', 'children': ['166', '172']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'string', 'children': [], 'value': '"dateformat"'},{'id': '175', 'type': 'if_statement', 'children': ['176', '178', '186', '199']},{'id': '176', 'type': 'not_operator', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'color'},{'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': 'stream_handler'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'setFormatter'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '186', 'type': 'elif_clause', 'children': ['187', '191']},{'id': '187', 'type': 'boolean_operator', 'children': ['188', '189'], 'value': 'and'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '189', 'type': 'not_operator', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'COLORS'},{'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': 'ImportError'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'concatenated_string', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': '"Missing coloredlogs module. Please install with "'},{'id': '198', 'type': 'string', 'children': [], 'value': '"pip to use colors in logging."'},{'id': '199', 'type': 'else_clause', 'children': ['200']},{'id': '200', 'type': 'block', 'children': ['201', '275', '279']},{'id': '201', 'type': 'class_definition', 'children': ['202', '203', '207']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ColoredBenchFormatter'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'coloredlogs'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ColoredFormatter'},{'id': '207', 'type': 'block', 'children': ['208', '216']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'converter'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'},{'id': '216', 'type': 'function_definition', 'children': ['217', '218', '224']},{'id': '217', 'type': 'function_name', 'children': [], 'value': 'formatTime'},{'id': '218', 'type': 'parameters', 'children': ['219', '220', '221']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '221', 'type': 'default_parameter', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '223', 'type': 'None', 'children': []},{'id': '224', 'type': 'block', 'children': ['225', '241', '264', '273']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'date_and_time'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'converter'},{'id': '232', 'type': 'argument_list', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'utc'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'in'},{'id': '243', 'type': 'string', 'children': [], 'value': '"%F"'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '245', 'type': 'block', 'children': ['246', '254']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'msec'},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '%'},{'id': '250', 'type': 'string', 'children': [], 'value': '"%03d"'},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'msecs'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': '"%F"'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'msec'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'str_time'},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'date_and_time'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '273', 'type': 'return_statement', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'str_time'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'COLOR_ON'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'setFormatter'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'ColoredBenchFormatter'},{'id': '287', 'type': 'argument_list', 'children': ['288', '299', '310', '311']},{'id': '288', 'type': 'call', 'children': ['289', '297']},{'id': '289', 'type': 'attribute', 'children': ['290', '296']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'string', 'children': [], 'value': '"format"'},{'id': '299', 'type': 'call', 'children': ['300', '308']},{'id': '300', 'type': 'attribute', 'children': ['301', '307']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'string', 'children': [], 'value': '"dateformat"'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'LEVEL_FORMATS'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'FIELD_STYLES'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'SILENT_ON'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_LEVEL'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '320', 'type': 'if_statement', 'children': ['321', '323']},{'id': '321', 'type': 'not_operator', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'no_file'},{'id': '323', 'type': 'block', 'children': ['324', '343', '363']},{'id': '324', 'type': 'try_statement', 'children': ['325', '333']},{'id': '325', 'type': 'block', 'children': ['326']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'LOGPATHDIR'},{'id': '333', 'type': 'except_clause', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'raise_statement', 'children': ['337']},{'id': '337', 'type': 'call', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '339', 'type': 'argument_list', 'children': ['340']},{'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '%'},{'id': '341', 'type': 'string', 'children': [], 'value': '"Log path %s already exists."'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'LOGPATHDIR'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '346', 'type': 'call', 'children': ['347', '360']},{'id': '347', 'type': 'attribute', 'children': ['348', '359']},{'id': '348', 'type': 'call', 'children': ['349', '357']},{'id': '349', 'type': 'attribute', 'children': ['350', '356']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'string', 'children': [], 'value': '"file"'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '360', 'type': 'argument_list', 'children': ['361', '362']},{'id': '361', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '362', 'type': 'string', 'children': [], 'value': '"icetea.log"'},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'assignment', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': '_add_filehandler'},{'id': '368', 'type': 'argument_list', 'children': ['369', '370', '374', '375']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'get_base_logfilename'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'formatter'},{'id': '375', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '376', 'type': 'if_statement', 'children': ['377', '381', '391', '403']},{'id': '377', 'type': 'boolean_operator', 'children': ['378', '379'], 'value': 'and'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '379', 'type': 'not_operator', 'children': ['380']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '381', 'type': 'block', 'children': ['382']},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '391', 'type': 'elif_clause', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '393', 'type': 'block', 'children': ['394']},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'call', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'WARN'},{'id': '403', 'type': 'else_clause', 'children': ['404']},{'id': '404', 'type': 'block', 'children': ['405']},{'id': '405', 'type': 'expression_statement', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'setLevel'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'call', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '413', 'type': 'argument_list', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '415', 'type': 'call', 'children': ['416', '424']},{'id': '416', 'type': 'attribute', 'children': ['417', '423']},{'id': '417', 'type': 'call', 'children': ['418', '421']},{'id': '418', 'type': 'attribute', 'children': ['419', '420']},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'LOGGING_CONFIG'},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '421', 'type': 'argument_list', 'children': ['422']},{'id': '422', 'type': 'string', 'children': [], 'value': '"IceteaManager"'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '424', 'type': 'argument_list', 'children': ['425']},{'id': '425', 'type': 'string', 'children': [], 'value': '"level"'},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'addHandler'},{'id': '431', 'type': 'argument_list', 'children': ['432']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'stream_handler'},{'id': '433', 'type': 'expression_statement', 'children': ['434']},{'id': '434', 'type': 'assignment', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'TRUNCATE_LOG'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'truncate'},{'id': '437', 'type': 'if_statement', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'TRUNCATE_LOG'},{'id': '439', 'type': 'block', 'children': ['440']},{'id': '440', 'type': 'expression_statement', 'children': ['441']},{'id': '441', 'type': 'call', 'children': ['442', '445']},{'id': '442', 'type': 'attribute', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'icetealogger'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'addFilter'},{'id': '445', 'type': 'argument_list', 'children': ['446']},{'id': '446', 'type': 'call', 'children': ['447', '448']},{'id': '447', 'type': 'identifier', 'children': [], 'value': 'ContextFilter'},{'id': '448', 'type': 'argument_list', 'children': []},{'id': '449', 'type': 'expression_statement', 'children': ['450']},{'id': '450', 'type': 'assignment', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'STANDALONE_LOGGING'},{'id': '452', 'type': 'False', 'children': []} | def init_base_logging(directory="./log", verbose=0, silent=False, color=False, no_file=False,
truncate=True, config_location=None):
global LOGPATHDIR
global STANDALONE_LOGGING
global TRUNCATE_LOG
global COLOR_ON
global SILENT_ON
global VERBOSE_LEVEL
if config_location:
try:
_read_config(config_location)
except IOError as error:
raise IOError("Unable to read from configuration file {}: {}".format(config_location,
error))
except jsonschema.SchemaError as error:
raise jsonschema.SchemaError("Logging configuration schema "
"file malformed: {}".format(error))
LOGPATHDIR = os.path.join(directory, datetime.datetime.now().strftime(
"%Y-%m-%d_%H%M%S.%f").rstrip("0"))
icetealogger = logging.getLogger("icetea")
icetealogger.propagate = False
icetealogger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
formatter = BenchFormatter(LOGGING_CONFIG.get("IceteaManager").get("format"),
LOGGING_CONFIG.get("IceteaManager").get("dateformat"))
if not color:
stream_handler.setFormatter(formatter)
elif color and not COLORS:
raise ImportError("Missing coloredlogs module. Please install with "
"pip to use colors in logging.")
else:
class ColoredBenchFormatter(coloredlogs.ColoredFormatter):
converter = datetime.datetime.fromtimestamp
def formatTime(self, record, datefmt=None):
date_and_time = self.converter(record.created, tz=pytz.utc)
if "%F" in datefmt:
msec = "%03d" % record.msecs
datefmt = datefmt.replace("%F", msec)
str_time = date_and_time.strftime(datefmt)
return str_time
COLOR_ON = color
stream_handler.setFormatter(ColoredBenchFormatter(
LOGGING_CONFIG.get("IceteaManager").get("format"),
LOGGING_CONFIG.get("IceteaManager").get("dateformat"),
LEVEL_FORMATS, FIELD_STYLES))
SILENT_ON = silent
VERBOSE_LEVEL = verbose
if not no_file:
try:
os.makedirs(LOGPATHDIR)
except OSError:
raise OSError("Log path %s already exists." % LOGPATHDIR)
filename = LOGGING_CONFIG.get("IceteaManager").get("file").get("name", "icetea.log")
icetealogger = _add_filehandler(icetealogger, get_base_logfilename(filename),
formatter, "IceteaManager")
if verbose and not silent:
stream_handler.setLevel(logging.DEBUG)
elif silent:
stream_handler.setLevel(logging.WARN)
else:
stream_handler.setLevel(getattr(logging, LOGGING_CONFIG.get("IceteaManager").get("level")))
icetealogger.addHandler(stream_handler)
TRUNCATE_LOG = truncate
if TRUNCATE_LOG:
icetealogger.addFilter(ContextFilter())
STANDALONE_LOGGING = False |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assertJsonContains'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'jsonStr'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18', '87']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'jsonStr'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'try_statement', 'children': ['20', '61']},{'id': '20', 'type': 'block', 'children': ['21', '30']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'jsonStr'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'raise_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'TestStepFail'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '44', '47'], 'value': 'if'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'format_message'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'binary_operator', 'children': ['48', '52'], 'value': '%'},{'id': '48', 'type': 'concatenated_string', 'children': ['49', '50', '51']},{'id': '49', 'type': 'string', 'children': [], 'value': '"Assert: "'},{'id': '50', 'type': 'string', 'children': [], 'value': '"Key : %s is not "'},{'id': '51', 'type': 'string', 'children': [], 'value': '"in : %s"'},{'id': '52', 'type': 'tuple', 'children': ['53', '57']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'jsonStr'},{'id': '61', 'type': 'except_clause', 'children': ['62', '68']},{'id': '62', 'type': 'as_pattern', 'children': ['63', '66']},{'id': '63', 'type': 'tuple', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '66', 'type': 'as_pattern_target', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'raise_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'TestStepFail'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'conditional_expression', 'children': ['74', '78', '81'], 'value': 'if'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'format_message'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'},{'id': '82', 'type': 'string', 'children': [], 'value': '"Unable to parse json "'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'TestStepFail'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '98', '101'], 'value': 'if'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'format_message'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'string', 'children': [], 'value': '"Json string is empty"'} | def assertJsonContains(jsonStr=None, key=None, message=None):
if jsonStr is not None:
try:
data = json.loads(jsonStr)
if key not in data:
raise TestStepFail(
format_message(message) if message is not None else "Assert: "
"Key : %s is not "
"in : %s" % (str(key),
str(jsonStr)))
except (TypeError, ValueError) as e:
raise TestStepFail(
format_message(message) if message is not None else "Unable to parse json "+str(e))
else:
raise TestStepFail(
format_message(message) if message is not None else "Json string is empty") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_read_fd'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_descr'},{'id': '5', 'type': 'block', 'children': ['6', '58', '172']},{'id': '6', 'type': 'try_statement', 'children': ['7', '20']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'file_descr'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '*'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '20', 'type': 'except_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '22', 'type': 'block', 'children': ['23', '32', '56']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'NonBlockingStreamReader'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_get_sd'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'file_descr'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '43']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'has_error'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '49']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'is'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'if_statement', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '60', 'type': 'block', 'children': ['61', '70', '77', '101', '107', '120', '158', '167']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'NonBlockingStreamReader'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_get_sd'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'file_descr'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'if_statement', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'IS_PYTHON3'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'try_statement', 'children': ['81', '91']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'string', 'children': [], 'value': '"ascii"'},{'id': '91', 'type': 'except_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'augmented_assignment', 'children': ['103', '106'], 'value': '+='},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'split'},{'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': 'stream_desc'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'linesep'},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '128']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '124', 'type': 'slice', 'children': ['125', '126']},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'unary_operator', 'children': ['127'], 'value': '-'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'block', 'children': ['129', '145']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'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': 'stream_desc'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'read_queue'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'appendleft'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'strip_escape'},{'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': 'line'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'if_statement', 'children': ['146', '151']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': 'is'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'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': 'stream_desc'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'stream_desc'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'buf'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '165', 'type': 'unary_operator', 'children': ['166'], 'value': '-'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'} | def _read_fd(file_descr):
try:
line = os.read(file_descr, 1024 * 1024)
except OSError:
stream_desc = NonBlockingStreamReader._get_sd(file_descr)
if stream_desc is not None:
stream_desc.has_error = True
if stream_desc.callback is not None:
stream_desc.callback()
return 0
if line:
stream_desc = NonBlockingStreamReader._get_sd(file_descr)
if stream_desc is None:
return 0
if IS_PYTHON3:
try:
line = line.decode("ascii")
except UnicodeDecodeError:
line = repr(line)
stream_desc.buf += line
split = stream_desc.buf.split(os.linesep)
for line in split[:-1]:
stream_desc.read_queue.appendleft(strip_escape(line.strip()))
if stream_desc.callback is not None:
stream_desc.callback()
stream_desc.buf = split[-1]
return len(line)
return 0 |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'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': 'args'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15', '26', '36', '60', '66', '99', '116', '129', '179', '228', '263', '274', '326']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'EXIT_SUCCESS'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '20', 'type': 'conditional_expression', 'children': ['21', '22', '23'], 'value': 'if'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '26', 'type': 'if_statement', 'children': ['27', '33']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'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': 'check_args'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '36', 'type': 'if_statement', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '57']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '51'], 'value': 'and'},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tc'},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'suite'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get_fw_version'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'if_statement', 'children': ['67', '74', '82']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '73'], 'value': 'and'},{'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': 'args'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '74', 'type': 'block', 'children': ['75', '80']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '91']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'and'},{'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': 'version'},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '91', 'type': 'block', 'children': ['92', '97']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Unable to get version. Have you installed Icetea correctly?"'},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'conditional_expression', 'children': ['108', '114', '115'], 'value': 'if'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': '"Using Icetea version {}"'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '115', 'type': 'string', 'children': [], 'value': '"Unable to get Icetea version. Is Icetea installed?"'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_init_cloud'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '129', 'type': 'if_statement', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'listsuites'},{'id': '135', 'type': 'block', 'children': ['136', '150', '177']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'table'},{'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': 'list_suites'},{'id': '143', 'type': 'argument_list', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'suitedir'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154', '170']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155', '164']},{'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': 'logger'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '"No suites found!"'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'EXIT_FAIL'},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '179', 'type': 'try_statement', 'children': ['180', '200']},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'testsuite'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'TestSuite'},{'id': '186', 'type': 'argument_list', 'children': ['187', '192', '195']},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'cloud_module'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '200', 'type': 'except_clause', 'children': ['201', '205']},{'id': '201', 'type': 'as_pattern', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'SuiteException'},{'id': '203', 'type': 'as_pattern_target', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '205', 'type': 'block', 'children': ['206', '220', '226']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'string', 'children': [], 'value': '"Something went wrong in suite creation! {}"'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'EXIT_INCONC'},{'id': '226', 'type': 'return_statement', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '228', 'type': 'if_statement', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '234', 'type': 'block', 'children': ['235', '248', '256', '261']},{'id': '235', 'type': 'if_statement', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'testsuite'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'update_testcases'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'testcases'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'testsuite'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'list_testcases'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'testcases'},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'runtestsuite'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'testsuite'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'testsuite'},{'id': '274', 'type': 'if_statement', 'children': ['275', '277', '284', '305']},{'id': '275', 'type': 'not_operator', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'EXIT_SUCCESS'},{'id': '284', 'type': 'elif_clause', 'children': ['285', '298']},{'id': '285', 'type': 'boolean_operator', 'children': ['286', '291'], 'value': 'and'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'failure_count'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '297'], 'value': 'is'},{'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': 'args'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'failure_return_value'},{'id': '297', 'type': 'True', 'children': []},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'EXIT_FAIL'},{'id': '305', 'type': 'elif_clause', 'children': ['306', '319']},{'id': '306', 'type': 'boolean_operator', 'children': ['307', '312'], 'value': 'and'},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'inconclusive_count'},{'id': '311', 'type': 'argument_list', 'children': []},{'id': '312', 'type': 'comparison_operator', 'children': ['313', '318'], 'value': 'is'},{'id': '313', 'type': 'attribute', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'failure_return_value'},{'id': '318', 'type': 'True', 'children': []},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'ExitCodes'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'EXIT_INCONC'},{'id': '326', 'type': 'return_statement', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'retcodesummary'} | def run(self, args=None):
retcodesummary = ExitCodes.EXIT_SUCCESS
self.args = args if args else self.args
if not self.check_args():
return retcodesummary
if self.args.clean:
if not self.args.tc and not self.args.suite:
return retcodesummary
version = get_fw_version()
if self.args.version and version:
print(version)
return retcodesummary
elif self.args.version and not version:
print("Unable to get version. Have you installed Icetea correctly?")
return retcodesummary
self.logger.info("Using Icetea version {}".format(version) if version
else "Unable to get Icetea version. Is Icetea installed?")
cloud = self._init_cloud(self.args.cloud)
if self.args.listsuites:
table = self.list_suites(self.args.suitedir, cloud)
if table is None:
self.logger.error("No suites found!")
retcodesummary = ExitCodes.EXIT_FAIL
else:
print(table)
return retcodesummary
try:
testsuite = TestSuite(logger=self.logger, cloud_module=cloud, args=self.args)
except SuiteException as error:
self.logger.error("Something went wrong in suite creation! {}".format(error))
retcodesummary = ExitCodes.EXIT_INCONC
return retcodesummary
if self.args.list:
if self.args.cloud:
testsuite.update_testcases()
testcases = testsuite.list_testcases()
print(testcases)
return retcodesummary
results = self.runtestsuite(testsuite=testsuite)
if not results:
retcodesummary = ExitCodes.EXIT_SUCCESS
elif results.failure_count() and self.args.failure_return_value is True:
retcodesummary = ExitCodes.EXIT_FAIL
elif results.inconclusive_count() and self.args.failure_return_value is True:
retcodesummary = ExitCodes.EXIT_INCONC
return retcodesummary |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_object_graphs_by_class'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'classlist'},{'id': '5', 'type': 'block', 'children': ['6', '18', '22', '35']},{'id': '6', 'type': 'try_statement', 'children': ['7', '14']},{'id': '7', 'type': 'block', 'children': ['8', '11']},{'id': '8', 'type': 'import_statement', 'children': ['9']},{'id': '9', 'type': 'dotted_name', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'objgraph'},{'id': '11', 'type': 'import_statement', 'children': ['12']},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'gc'},{'id': '14', 'type': 'except_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'graphcount'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'if_statement', 'children': ['23', '29']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'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': 'classlist'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'classlist'},{'id': '33', 'type': 'list', 'children': ['34'], 'value': '[classlist]'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'classlist'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'class_item'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'classlist'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '46']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'gc'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_objects'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'if_statement', 'children': ['48', '53']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'class_item'},{'id': '53', 'type': 'block', 'children': ['54', '58', '78']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'augmented_assignment', 'children': ['56', '57'], 'value': '+='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'graphcount'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'objgraph'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'show_refs'},{'id': '63', 'type': 'argument_list', 'children': ['64', '66']},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[obj]'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'},{'id': '69', 'type': 'string', 'children': [], 'value': "'%d_%s_%d_refs.png'"},{'id': '70', 'type': 'tuple', 'children': ['71', '72', '77']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ogcounter'},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'graphcount'},{'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': 'objgraph'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'show_backrefs'},{'id': '83', 'type': 'argument_list', 'children': ['84', '86']},{'id': '84', 'type': 'list', 'children': ['85'], 'value': '[obj]'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': "'%d_%s_%d_backrefs.png'"},{'id': '90', 'type': 'tuple', 'children': ['91', '92', '97']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ogcounter'},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '96', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'graphcount'} | def generate_object_graphs_by_class(classlist):
try:
import objgraph
import gc
except ImportError:
return
graphcount = 0
if not isinstance(classlist, list):
classlist = [classlist]
for class_item in classlist:
for obj in gc.get_objects():
if isinstance(obj, class_item):
graphcount += 1
objgraph.show_refs([obj], filename='%d_%s_%d_refs.png' % (
ogcounter, obj.__class__.__name__, graphcount))
objgraph.show_backrefs([obj], filename='%d_%s_%d_backrefs.png' % (
ogcounter, obj.__class__.__name__, graphcount)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_wait_for_exec_ready'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '113', '165', '189', '195']},{'id': '6', 'type': 'while_statement', 'children': ['7', '22']},{'id': '7', 'type': 'boolean_operator', 'children': ['8', '17'], 'value': 'and'},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'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': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'integer', 'children': [], 'value': '1'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': '!='},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'block', 'children': ['23', '87', '107']},{'id': '23', 'type': 'if_statement', 'children': ['24', '39']},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '30'], 'value': 'and'},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '!='},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': '<'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '59', '70', '76']},{'id': '40', 'type': 'if_statement', 'children': ['41', '44', '53']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'prev'},{'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': 'cmd'},{'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': 'prev'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'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': 'cmd'},{'id': '58', 'type': 'string', 'children': [], 'value': '"???"'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '66']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '+'},{'id': '68', 'type': 'string', 'children': [], 'value': '"CMD timeout: "'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'TestStepTimeout'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '86'], 'value': '+'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '+'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'string', 'children': [], 'value': '" CMD timeout: "'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', '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': 'logger'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'concatenated_string', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Waiting for response... "'},{'id': '97', 'type': 'string', 'children': [], 'value': '"timeout=%d"'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '-'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'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': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_dut_is_alive'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '120']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '118'], 'value': '=='},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'id': '118', 'type': 'unary_operator', 'children': ['119'], 'value': '-'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'block', 'children': ['121', '145', '154']},{'id': '121', 'type': 'if_statement', 'children': ['122', '127']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': 'is'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128', '139']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'set_response'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'CliResponse'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'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': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'string', 'children': [], 'value': '"No response received, DUT died"'},{'id': '154', 'type': 'raise_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'TestStepError'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'binary_operator', 'children': ['159', '164'], 'value': '+'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'string', 'children': [], 'value': '"No response received, DUT "'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '164', 'type': 'string', 'children': [], 'value': '" died"'},{'id': '165', 'type': 'if_statement', 'children': ['166', '171']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '170'], 'value': 'is'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '183']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'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': 'query_async_response'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'set_response'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'},{'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': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '188', 'type': 'None', 'children': []},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '194', 'type': 'integer', 'children': [], 'value': '0'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'response_coming_in'} | def _wait_for_exec_ready(self):
while not self.response_received.wait(1) and self.query_timeout != 0:
if self.query_timeout != 0 and self.query_timeout < self.get_time():
if self.prev:
cmd = self.prev.cmd
else:
cmd = "???"
self.logger.error("CMD timeout: "+ cmd)
self.query_timeout = 0
raise TestStepTimeout(self.name + " CMD timeout: " + cmd)
self.logger.debug("Waiting for response... "
"timeout=%d", self.query_timeout - self.get_time())
self._dut_is_alive()
if self.response_coming_in == -1:
if self.query_async_response is not None:
self.query_async_response.set_response(CliResponse())
self.query_async_response = None
self.logger.error("No response received, DUT died")
raise TestStepError("No response received, DUT "+self.name+" died")
if self.query_async_response is not None:
self.query_async_response.set_response(self.response_coming_in)
self.query_async_response = None
self.query_timeout = 0
return self.response_coming_in |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute_command'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '88', '149', '157', '176', '182', '193', '218', '233', '240', '270', '313']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '15', 'type': 'block', 'children': ['16', '20', '24', '28', '65']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '19', 'type': 'integer', 'children': [], 'value': '50'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'asynchronous'},{'id': '27', 'type': 'False', 'children': []},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '36', '43', '54']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'string', 'children': [], 'value': "'wait'"},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'elif_clause', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'string', 'children': [], 'value': "'timeout'"},{'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': 'timeout'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'elif_clause', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'string', 'children': [], 'value': "'asynchronous'"},{'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': 'asynchronous'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'CliRequest'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72', '79', '82', '85']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'asynchronous'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'asynchronous'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '92', 'type': 'block', 'children': ['93', '101']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_wait_for_exec_ready'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '111']},{'id': '102', 'type': 'boolean_operator', 'children': ['103', '106'], 'value': 'and'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': 'is'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'block', 'children': ['112', '143']},{'id': '112', 'type': 'if_statement', 'children': ['113', '120']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': '!='},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '120', 'type': 'block', 'children': ['121', '138']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'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': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '128', 'type': 'argument_list', 'children': ['129', '132', '135']},{'id': '129', 'type': 'concatenated_string', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': '"Asynch call returned unexpected result, "'},{'id': '131', 'type': 'string', 'children': [], 'value': '"expected %d was %d"'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'retcode'},{'id': '138', 'type': 'raise_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'TestStepFail'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'string', 'children': [], 'value': '"Asynch call returned unexpected result"'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '148', 'type': 'None', 'children': []},{'id': '149', 'type': 'expression_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': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'response_received'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'query_timeout'},{'id': '162', 'type': 'conditional_expression', 'children': ['163', '172', '175'], 'value': 'if'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '169'], 'value': '+'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '185', 'type': 'conditional_expression', 'children': ['186', '189', '192'], 'value': 'if'},{'id': '186', 'type': 'concatenated_string', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': '"Async CMD {}, "'},{'id': '188', 'type': 'string', 'children': [], 'value': '"timeout={}, time={}"'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'asynchronous'},{'id': '192', 'type': 'string', 'children': [], 'value': '"CMD {}, timeout={}, time={}"'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '200', 'type': 'argument_list', 'children': ['201', '204', '210']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'query_timeout'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'get_time'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '229', 'type': 'dictionary', 'children': ['230']},{'id': '230', 'type': 'pair', 'children': ['231', '232']},{'id': '231', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '232', 'type': 'string', 'children': [], 'value': "'<->'"},{'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': 'Dut'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'process_dut'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'if_statement', 'children': ['241', '246']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '245'], 'value': 'is'},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'asynchronous'},{'id': '245', 'type': 'True', 'children': []},{'id': '246', 'type': 'block', 'children': ['247', '255', '262', '268']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'expected_retcode'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'async_response'},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'CliAsyncResponse'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'async_response'},{'id': '268', 'type': 'return_statement', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'async_response'},{'id': '270', 'type': 'if_statement', 'children': ['271', '276']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '275'], 'value': 'is'},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '275', 'type': 'False', 'children': []},{'id': '276', 'type': 'block', 'children': ['277', '285', '303', '309']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'query_async_expected'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'expected_retcode'},{'id': '285', 'type': 'if_statement', 'children': ['286', '291']},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '290'], 'value': 'is'},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '290', 'type': 'None', 'children': []},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'set_response'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'CliResponse'},{'id': '302', 'type': 'argument_list', 'children': []},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'assignment', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'query_async_response'},{'id': '308', 'type': 'None', 'children': []},{'id': '309', 'type': 'return_statement', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'CliResponse'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'return_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': '_wait_for_exec_ready'},{'id': '318', 'type': 'argument_list', 'children': []} | def execute_command(self, req, **kwargs):
if isinstance(req, string_types):
timeout = 50
wait = True
asynchronous = False
for key in kwargs:
if key == 'wait':
wait = kwargs[key]
elif key == 'timeout':
timeout = kwargs[key]
elif key == 'asynchronous':
asynchronous = kwargs[key]
req = CliRequest(req,
timestamp=self.get_time(),
wait=wait,
timeout=timeout,
asynchronous=asynchronous)
if req.wait:
response = self._wait_for_exec_ready()
if response is not None and self.query_async_expected is not None:
if response.retcode != self.query_async_expected:
self.logger.error("Asynch call returned unexpected result, "
"expected %d was %d", self.query_async_expected,
response.retcode)
raise TestStepFail("Asynch call returned unexpected result")
self.query_async_expected = None
self.response_received.clear()
self.query_timeout = self.get_time() + req.timeout if req.wait else 0
self.query = req
msg = "Async CMD {}, " \
"timeout={}, time={}" if req.asynchronous else "CMD {}, timeout={}, time={}"
msg = msg.format(req.cmd, int(self.query_timeout), int(self.get_time()))
self.logger.debug(msg, extra={'type': '<->'})
Dut.process_dut(self)
if req.asynchronous is True:
self.query_async_expected = req.expected_retcode
async_response = CliAsyncResponse(self)
self.query_async_response = async_response
return async_response
if req.wait is False:
self.query_async_expected = req.expected_retcode
if self.query_async_response is not None:
self.query_async_response.set_response(CliResponse())
self.query_async_response = None
return CliResponse()
return self._wait_for_exec_ready() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.