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', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ID_ONLY'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'SHALLOW'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'order_fields'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'block', 'children': ['31', '45', '59', '73', '111', '130', '194', '216', '271']},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'SHAPE_CHOICES'},{'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': 'ValueError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '%'},{'id': '41', 'type': 'string', 'children': [], 'value': '"\'shape\' %s must be one of %s"'},{'id': '42', 'type': 'tuple', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'SHAPE_CHOICES'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'not'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ITEM_TRAVERSAL_CHOICES'},{'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': 'ValueError'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': '"\'depth\' %s must be one of %s"'},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ITEM_TRAVERSAL_CHOICES'},{'id': '59', 'type': 'if_statement', 'children': ['60', '64']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '64', 'type': 'block', 'children': ['65', '72']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'Folder list is empty'"},{'id': '72', 'type': 'return_statement', 'children': []},{'id': '73', 'type': 'if_statement', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '75', 'type': 'block', 'children': ['76', '89']},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'validate_item_field'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'if_statement', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'is_complex'},{'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': 'ValueError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': '"find_items() does not support field \'%s\'. Use fetch() instead"'},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '111', 'type': 'if_statement', 'children': ['112', '122']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '116'], 'value': 'and'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'not_operator', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'CalendarView'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'raise_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'},{'id': '128', 'type': 'string', 'children': [], 'value': '"\'calendar_view\' %s must be a CalendarView instance"'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '130', 'type': 'if_statement', 'children': ['131', '136', '145', '171']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'is_empty'},{'id': '135', 'type': 'argument_list', 'children': []},{'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': 'restriction'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'elif_clause', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '149', 'type': 'block', 'children': ['150', '154']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'Restriction'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161', '166']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'applies_to'},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'Restriction'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ITEMS'},{'id': '171', 'type': 'else_clause', 'children': ['172']},{'id': '172', 'type': 'block', 'children': ['173', '190']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'Restriction'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '185']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'applies_to'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'Restriction'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'ITEMS'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '193', 'type': 'None', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201', '204', '207', '208', '209', '210']},{'id': '200', 'type': 'string', 'children': [], 'value': "'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)'"},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '210', 'type': 'conditional_expression', 'children': ['211', '214', '215'], 'value': 'if'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'q'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '215', 'type': 'None', 'children': []},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '219', 'type': 'call', 'children': ['220', '238']},{'id': '220', 'type': 'attribute', 'children': ['221', '237']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'FindItem'},{'id': '223', 'type': 'argument_list', 'children': ['224', '229', '234']},{'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'folders'},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'page_size'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '238', 'type': 'argument_list', 'children': ['239', '242', '245', '248', '251', '254', '257', '260', '268']},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'restriction'},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'order_fields'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'order_fields'},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '262', 'type': 'conditional_expression', 'children': ['263', '266', '267'], 'value': 'if'},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'calendar_view'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'max_items'},{'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '271', 'type': 'if_statement', 'children': ['272', '279', '299']},{'id': '272', 'type': 'boolean_operator', 'children': ['273', '276'], 'value': 'and'},{'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': '=='},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'ID_ONLY'},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': 'is'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'additional_fields'},{'id': '278', 'type': 'None', 'children': []},{'id': '279', 'type': 'block', 'children': ['280']},{'id': '280', 'type': 'for_statement', 'children': ['281', '282', '283']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'yield', 'children': ['286']},{'id': '286', 'type': 'conditional_expression', 'children': ['287', '288', '293'], 'value': 'if'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'Item'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'id_from_xml'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '299', 'type': 'else_clause', 'children': ['300']},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'for_statement', 'children': ['302', '303', '304']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'if_statement', 'children': ['306', '311', '315']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '308', 'type': 'argument_list', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'yield', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '315', 'type': 'else_clause', 'children': ['316']},{'id': '316', 'type': 'block', 'children': ['317']},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'yield', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '330']},{'id': '320', 'type': 'attribute', 'children': ['321', '329']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'Folder'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'item_model_from_tag'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'from_xml'},{'id': '330', 'type': 'argument_list', 'children': ['331', '334']},{'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'account'},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'account'}
def find_items(self, q, shape=ID_ONLY, depth=SHALLOW, additional_fields=None, order_fields=None, calendar_view=None, page_size=None, max_items=None, offset=0): if shape not in SHAPE_CHOICES: raise ValueError("'shape' %s must be one of %s" % (shape, SHAPE_CHOICES)) if depth not in ITEM_TRAVERSAL_CHOICES: raise ValueError("'depth' %s must be one of %s" % (depth, ITEM_TRAVERSAL_CHOICES)) if not self.folders: log.debug('Folder list is empty') return if additional_fields: for f in additional_fields: self.validate_item_field(field=f) for f in additional_fields: if f.field.is_complex: raise ValueError("find_items() does not support field '%s'. Use fetch() instead" % f.field.name) if calendar_view is not None and not isinstance(calendar_view, CalendarView): raise ValueError("'calendar_view' %s must be a CalendarView instance" % calendar_view) if q.is_empty(): restriction = None query_string = None elif q.query_string: restriction = None query_string = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS) else: restriction = Restriction(q, folders=self.folders, applies_to=Restriction.ITEMS) query_string = None log.debug( 'Finding %s items in folders %s (shape: %s, depth: %s, additional_fields: %s, restriction: %s)', self.folders, self.account, shape, depth, additional_fields, restriction.q if restriction else None, ) items = FindItem(account=self.account, folders=self.folders, chunk_size=page_size).call( additional_fields=additional_fields, restriction=restriction, order_fields=order_fields, shape=shape, query_string=query_string, depth=depth, calendar_view=calendar_view, max_items=calendar_view.max_items if calendar_view else max_items, offset=offset, ) if shape == ID_ONLY and additional_fields is None: for i in items: yield i if isinstance(i, Exception) else Item.id_from_xml(i) else: for i in items: if isinstance(i, Exception): yield i else: yield Folder.item_model_from_tag(i.tag).from_xml(elem=i, account=self.account)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '19', '34']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'in'},{'id': '9', 'type': 'string', 'children': [], 'value': "'reldepth'"},{'id': '10', 'type': 'subscript', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'gosubdag'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'prt_attr'},{'id': '18', 'type': 'string', 'children': [], 'value': "'flds'"},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'list', 'children': ['22', '25', '31'], 'value': '[ntd.NS, -1*ntd.dcnt, ntd.reldepth]'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NS'},{'id': '25', 'type': 'binary_operator', 'children': ['26', '28'], 'value': '*'},{'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dcnt'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'reldepth'},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'list', 'children': ['38', '41', '47'], 'value': '[ntd.NS, -1*ntd.dcnt, ntd.depth]'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'NS'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '44'], 'value': '*'},{'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dcnt'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ntd'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'depth'}
def sortby(self, ntd): if 'reldepth' in self.grprobj.gosubdag.prt_attr['flds']: return [ntd.NS, -1*ntd.dcnt, ntd.reldepth] else: return [ntd.NS, -1*ntd.dcnt, ntd.depth]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_nts_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '8', 'type': 'block', 'children': ['9', '13', '23']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'nts_flat'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'get_sorted_hdrgo2usrgos'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21', '22']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nts_flat'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nts_flat'}
def get_nts_sorted(self, hdrgo_prt, hdrgos, hdrgo_sort): nts_flat = [] self.get_sorted_hdrgo2usrgos(hdrgos, nts_flat, hdrgo_prt, hdrgo_sort) return nts_flat
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_hdrgo2usrgos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'flat_list'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '20', '30', '39', '68', '182']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted_hdrgos_usrgos'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'h2u_get'},{'id': '23', 'type': 'attribute', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'hdrgo2usrgos'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hdr_go2nt'},{'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': '_get_go2nt'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'hdr_go2nt'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '49', 'type': 'argument_list', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'hdr_go2nt'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'lambda', 'children': ['58', '60']},{'id': '58', 'type': 'lambda_parameters', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 't'},{'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': 'hdrgo_sortby'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'for_statement', 'children': ['69', '72', '73']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'hdrgo_id'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'hdrgo_nt'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hdr_go2nt'},{'id': '73', 'type': 'block', 'children': ['74', '97', '104']},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'flat_list'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'if_statement', 'children': ['80', '89']},{'id': '80', 'type': 'boolean_operator', 'children': ['81', '82'], 'value': 'or'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'in'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'hdrgo_id'},{'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': 'grprobj'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'usrgos'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'flat_list'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'hdrgo_nt'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'usrgos_unsorted'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'h2u_get'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'hdrgo_id'},{'id': '104', 'type': 'if_statement', 'children': ['105', '106', '171']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'usrgos_unsorted'},{'id': '106', 'type': 'block', 'children': ['107', '116', '140', '150', '162']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'usrgo2nt'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_get_go2nt'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'usrgos_unsorted'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'usrgont_sorted'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '121', 'type': 'argument_list', 'children': ['122', '127']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'usrgo2nt'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '129', 'type': 'lambda', 'children': ['130', '132']},{'id': '130', 'type': 'lambda_parameters', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'usrgo_sortby'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '145']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'usrgos_sorted'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'usrnts_sorted'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'list_splat', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'usrgont_sorted'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'flat_list'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'flat_list'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'usrnts_sorted'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sorted_hdrgos_usrgos'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'tuple', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'hdrgo_id'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'usrgos_sorted'},{'id': '171', 'type': 'else_clause', 'children': ['172']},{'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': 'sorted_hdrgos_usrgos'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'tuple', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'hdrgo_id'},{'id': '181', 'type': 'list', 'children': [], 'value': '[]'},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cx'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'sorted_hdrgos_usrgos'}
def get_sorted_hdrgo2usrgos(self, hdrgos, flat_list=None, hdrgo_prt=True, hdrgo_sort=True): sorted_hdrgos_usrgos = [] h2u_get = self.grprobj.hdrgo2usrgos.get hdr_go2nt = self._get_go2nt(hdrgos) if hdrgo_sort is True: hdr_go2nt = sorted(hdr_go2nt.items(), key=lambda t: self.hdrgo_sortby(t[1])) for hdrgo_id, hdrgo_nt in hdr_go2nt: if flat_list is not None: if hdrgo_prt or hdrgo_id in self.grprobj.usrgos: flat_list.append(hdrgo_nt) usrgos_unsorted = h2u_get(hdrgo_id) if usrgos_unsorted: usrgo2nt = self._get_go2nt(usrgos_unsorted) usrgont_sorted = sorted(usrgo2nt.items(), key=lambda t: self.usrgo_sortby(t[1])) usrgos_sorted, usrnts_sorted = zip(*usrgont_sorted) if flat_list is not None: flat_list.extend(usrnts_sorted) sorted_hdrgos_usrgos.append((hdrgo_id, usrgos_sorted)) else: sorted_hdrgos_usrgos.append((hdrgo_id, [])) return cx.OrderedDict(sorted_hdrgos_usrgos)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_hdrgo_sortby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sortby'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '7', 'type': 'block', 'children': ['8', '15', '22']},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sortby'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sortby'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sortby'}
def _init_hdrgo_sortby(self, hdrgo_sortby, sortby): if hdrgo_sortby is not None: return hdrgo_sortby if sortby is not None: return sortby return self.sortby
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sortgo'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '23']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'in'},{'id': '8', 'type': 'string', 'children': [], 'value': "'sortgo'"},{'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': 'datobj'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'subscript', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'datobj'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '22', 'type': 'string', 'children': [], 'value': "'sortgo'"},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '36'], 'value': '+'},{'id': '25', 'type': 'subscript', 'children': ['26', '35']},{'id': '26', 'type': 'attribute', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'datobj'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'grprdflt'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'gosubdag'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'prt_attr'},{'id': '35', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '36', 'type': 'string', 'children': [], 'value': '"\\n"'}
def _get_sortgo(self): if 'sortgo' in self.datobj.kws: return self.datobj.kws['sortgo'] return self.datobj.grprdflt.gosubdag.prt_attr['sort'] + "\n"
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_section'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nts_section'},{'id': '6', 'type': 'block', 'children': ['7', '32', '47']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'is'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'section_sortby'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nts_section'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'lambda', 'children': ['22', '24']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sortgos'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'usrgo_sortby'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '32', 'type': 'if_statement', 'children': ['33', '44']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'or'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': 'is'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'section_sortby'},{'id': '38', 'type': 'False', 'children': []},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'section_sortby'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'nts_section'},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'nts_section'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'lambda', 'children': ['55', '57']},{'id': '55', 'type': 'lambda_parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'section_sortby'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'nt'}
def _get_sorted_section(self, nts_section): if self.section_sortby is True: return sorted(nts_section, key=lambda nt: self.sortgos.usrgo_sortby(nt)) if self.section_sortby is False or self.section_sortby is None: return nts_section return sorted(nts_section, key=lambda nt: self.section_sortby(nt))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sections_2dnt'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sec2d_go'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'list_comprehension', 'children': ['9', '17']},{'id': '9', 'type': 'tuple', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nm'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_ntgos_sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'gos'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nm'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'gos'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sec2d_go'}
def get_sections_2dnt(self, sec2d_go): return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ntgos_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '6', 'type': 'block', 'children': ['7', '15']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'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': 'grprobj'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19', '30']},{'id': '19', 'type': 'list_comprehension', 'children': ['20', '23', '26']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'go'},{'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'go'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '26', 'type': 'if_clause', 'children': ['27']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'go'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fncsortnt'}
def get_ntgos_sorted(self, hdrgos): go2nt = self.grprobj.go2nt return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sortobj'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'goea_results'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '8', 'type': 'block', 'children': ['9', '22', '34', '46', '65', '74', '93']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'nts_goea'},{'id': '12', 'type': 'call', 'children': ['13', '19']},{'id': '13', 'type': 'attribute', 'children': ['14', '18']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'MgrNtGOEAs'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'goea_results'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_goea_nts_prt'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'dictionary_splat', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'goids'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'generator_expression', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'GO'},{'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nts_goea'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '37', 'type': 'dictionary_comprehension', 'children': ['38', '43']},{'id': '38', 'type': 'pair', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'GO'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nts_goea'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Grouper'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '54', '57', '62']},{'id': '52', 'type': 'string', 'children': [], 'value': '"GOEA"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'goids'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'hdrobj'},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'grprdflt'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'gosubdag'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'go2nt'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'prt_summary'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sortobj'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'Sorter'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'section_sortby'},{'id': '83', 'type': 'lambda', 'children': ['84', '86']},{'id': '84', 'type': 'lambda_parameters', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pval_fld'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sortobj'}
def get_sortobj(self, goea_results, **kws): nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_relationships'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'goterm'},{'id': '6', 'type': 'block', 'children': ['7', '17', '28', '43']},{'id': '7', 'type': 'if_statement', 'children': ['8', '15']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'in'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'goterm'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'goids_seen'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'goids_seen'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'goterm'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '35']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'goterm_upper'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'goterm'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_goterms_upper'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'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': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_get_sorted_relationships'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'goterm_upper'},{'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': 'goterms_sorted'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'goterm'}
def _get_sorted_relationships(self, goterm): if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_dag'},{'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': 'out'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '21']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'out'}
def write_dag(self, out=sys.stdout): for rec in sorted(self.values()): print(rec, file=out)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_nts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nt_list'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'codekey'},{'id': '7', 'type': 'block', 'children': ['8', '28']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '11', 'type': 'lambda', 'children': ['12', '14']},{'id': '12', 'type': 'lambda_parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ev2idx'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '20', 'type': 'argument_list', 'children': ['21', '26']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nt'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'codekey'},{'id': '26', 'type': 'unary_operator', 'children': ['27'], 'value': '-'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'nt_list'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sortby'}
def sort_nts(self, nt_list, codekey): sortby = lambda nt: self.ev2idx.get(getattr(nt, codekey), -1) return sorted(nt_list, key=sortby)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prt_gos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'prt'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'kws_usr'},{'id': '12', 'type': 'block', 'children': ['13', '23', '37']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'desc2nts'},{'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': 'get_desc2nts'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'dictionary_splat', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kws_usr'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'prt_nts'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'desc2nts'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'prt'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kws_usr'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'prtfmt'"},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'desc2nts'}
def prt_gos(self, prt=sys.stdout, **kws_usr): desc2nts = self.get_desc2nts(**kws_usr) self.prt_nts(desc2nts, prt, kws_usr.get('prtfmt')) return desc2nts
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_nts_flat'},{'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': 'hdrgo_prt'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'use_sections'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '43', '59']},{'id': '12', 'type': 'if_statement', 'children': ['13', '21']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '19'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sectobj'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'use_sections'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sortgos'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_nts_sorted'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '40']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hdrgos'},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'grprobj'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_hdrgos'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '46']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'use_sections'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sectobj'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_sorted_nts_omit_section'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'hdrgo_prt'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'hdrgo_sort'},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'None', 'children': []}
def get_nts_flat(self, hdrgo_prt=True, use_sections=True): if self.sectobj is None or not use_sections: return self.sortgos.get_nts_sorted( hdrgo_prt, hdrgos=self.grprobj.get_hdrgos(), hdrgo_sort=True) if not use_sections: return self.sectobj.get_sorted_nts_omit_section(hdrgo_prt, hdrgo_sort=True) return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_adjust_prt_flds'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kws_xlsx'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'desc2nts'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'shade_hdrgos'},{'id': '8', 'type': 'block', 'children': ['9', '18', '28', '32', '43', '78']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'in'},{'id': '11', 'type': 'string', 'children': [], 'value': '"prt_flds"'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kws_xlsx'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'kws_xlsx'},{'id': '17', 'type': 'string', 'children': [], 'value': '"prt_flds"'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dont_print'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'list', 'children': ['25', '26', '27'], 'value': "['hdr_idx', 'is_hdrgo', 'is_usrgo']"},{'id': '25', 'type': 'string', 'children': [], 'value': "'hdr_idx'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'is_hdrgo'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'is_usrgo'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'prt_flds_adjusted'},{'id': '31', 'type': 'list', 'children': [], 'value': '[]'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'nt_flds'},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sortobj'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'get_fields'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'desc2nts'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'nt_fld'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nt_flds'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'not'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'nt_fld'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dont_print'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '56', '69']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'nt_fld'},{'id': '55', 'type': 'string', 'children': [], 'value': '"format_txt"'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'shade_hdrgos'},{'id': '60', 'type': 'True', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'prt_flds_adjusted'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'nt_fld'},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'prt_flds_adjusted'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nt_fld'},{'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': 'kws_xlsx'},{'id': '82', 'type': 'string', 'children': [], 'value': "'prt_flds'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'prt_flds_adjusted'}
def _adjust_prt_flds(self, kws_xlsx, desc2nts, shade_hdrgos): if "prt_flds" in kws_xlsx: return kws_xlsx["prt_flds"] dont_print = set(['hdr_idx', 'is_hdrgo', 'is_usrgo']) prt_flds_adjusted = [] nt_flds = self.sortobj.get_fields(desc2nts) for nt_fld in nt_flds: if nt_fld not in dont_print: if nt_fld == "format_txt": if shade_hdrgos is True: prt_flds_adjusted.append(nt_fld) else: prt_flds_adjusted.append(nt_fld) kws_xlsx['prt_flds'] = prt_flds_adjusted
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_shade_hdrgos'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'dictionary_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '6', 'type': 'block', 'children': ['7', '16', '25', '36', '51']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'in'},{'id': '9', 'type': 'string', 'children': [], 'value': "'shade_hdrgos'"},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '15', 'type': 'string', 'children': [], 'value': "'shade_hdrgos'"},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'},{'id': '18', 'type': 'string', 'children': [], 'value': "'hdrgo_prt'"},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '24', 'type': 'string', 'children': [], 'value': "'hdrgo_prt'"},{'id': '25', 'type': 'if_statement', 'children': ['26', '33']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '30'], 'value': 'and'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'string', 'children': [], 'value': "'section_sortby'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '32', 'type': 'string', 'children': [], 'value': "'section_sortby'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '48']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'in'},{'id': '39', 'type': 'string', 'children': [], 'value': "'top_n'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'kws'},{'id': '46', 'type': 'string', 'children': [], 'value': "'top_n'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'False', 'children': []},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'True', 'children': []}
def _get_shade_hdrgos(**kws): if 'shade_hdrgos' in kws: return kws['shade_hdrgos'] if 'hdrgo_prt' in kws: return kws['hdrgo_prt'] if 'section_sortby' in kws and kws['section_sortby']: return False if 'top_n' in kws and isinstance(kws['top_n'], int): return False return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dflt_sortby_objgoea'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'goea_res'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list', 'children': ['8', '13', '18', '23', '28'], 'value': "[getattr(goea_res, 'enrichment'),\n getattr(goea_res, 'namespace'),\n getattr(goea_res, 'p_uncorrected'),\n getattr(goea_res, 'depth'),\n getattr(goea_res, 'GO')]"},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'goea_res'},{'id': '12', 'type': 'string', 'children': [], 'value': "'enrichment'"},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'goea_res'},{'id': '17', 'type': 'string', 'children': [], 'value': "'namespace'"},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'goea_res'},{'id': '22', 'type': 'string', 'children': [], 'value': "'p_uncorrected'"},{'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': 'goea_res'},{'id': '27', 'type': 'string', 'children': [], 'value': "'depth'"},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'goea_res'},{'id': '32', 'type': 'string', 'children': [], 'value': "'GO'"}
def dflt_sortby_objgoea(goea_res): return [getattr(goea_res, 'enrichment'), getattr(goea_res, 'namespace'), getattr(goea_res, 'p_uncorrected'), getattr(goea_res, 'depth'), getattr(goea_res, 'GO')]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dflt_sortby_ntgoea'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'list', 'children': ['8', '11', '14', '17', '20'], 'value': '[ntgoea.enrichment,\n ntgoea.namespace,\n ntgoea.p_uncorrected,\n ntgoea.depth,\n ntgoea.GO]'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'enrichment'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'p_uncorrected'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ntgoea'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'GO'}
def dflt_sortby_ntgoea(ntgoea): return [ntgoea.enrichment, ntgoea.namespace, ntgoea.p_uncorrected, ntgoea.depth, ntgoea.GO]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'with_index'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'only_index'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '28', '38']},{'id': '19', 'type': 'import_from_statement', 'children': ['20', '24']},{'id': '20', 'type': 'relative_import', 'children': ['21', '22']},{'id': '21', 'type': 'import_prefix', 'children': []},{'id': '22', 'type': 'dotted_name', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'function_bases'},{'id': '24', 'type': 'aliased_import', 'children': ['25', '27']},{'id': '25', 'type': 'dotted_name', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_base'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'n_outputs'},{'id': '31', 'type': 'conditional_expression', 'children': ['32', '33', '37'], 'value': 'if'},{'id': '32', 'type': 'integer', 'children': [], 'value': '2'},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'with_index'},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'only_index'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_base'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44', '45', '46', '47']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'with_index'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'only_index'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'n_outputs'}
def sort(x, axis=-1, reverse=False, with_index=False, only_index=False): from .function_bases import sort as sort_base n_outputs = 2 if with_index and not only_index else 1 return sort_base(x, axis, reverse, with_index, only_index, n_outputs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'optimize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '27']},{'id': '6', 'type': 'with_statement', 'children': ['7', '17']},{'id': '7', 'type': 'with_clause', 'children': ['8']},{'id': '8', 'type': 'with_item', 'children': ['9']},{'id': '9', 'type': 'as_pattern', 'children': ['10', '15']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'LIBRARIES_FILE'},{'id': '14', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '15', 'type': 'as_pattern_target', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'libs_data'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'for_statement', 'children': ['28', '31', '36']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'libs_names'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'libs_data'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '46', '51', '73']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'libs'},{'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_libs'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '46', 'type': 'if_statement', 'children': ['47', '49']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'libs'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'continue_statement', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '58']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'libs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '60', '63']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'libs'},{'id': '63', 'type': 'if_clause', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '72'], 'value': 'in'},{'id': '65', 'type': 'list', 'children': ['66', '69'], 'value': '[lib.module_name, lib.func_name]'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'func_name'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'libs_names'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '82']},{'id': '75', 'type': 'attribute', 'children': ['76', '81']},{'id': '76', 'type': 'subscript', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'libs'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '85', 'type': 'lambda', 'children': ['86', '88']},{'id': '86', 'type': 'lambda_parameters', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'libs_names'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'list', 'children': ['94', '97'], 'value': '[lib.module_name, lib.func_name]'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'lib'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'func_name'}
def optimize(self): with open(LIBRARIES_FILE, 'r') as f: libs_data = json.load(f) for alg, libs_names in libs_data.items(): libs = self.get_libs(alg) if not libs: continue self.libs[alg] = [lib for lib in libs if [lib.module_name, lib.func_name] in libs_names] self.libs[alg].sort(key=lambda lib: libs_names.index([lib.module_name, lib.func_name]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_common_members'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '11', '15', '22', '26', '43', '50', '75', '89']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '8', 'type': 'binary_operator', 'children': ['9', '10'], 'value': '+'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'PREFIX'},{'id': '10', 'type': 'string', 'children': [], 'value': "'/common_members.json'"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted_json_data'},{'id': '14', 'type': 'dictionary', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'json_data'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'read_json'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '30', '35']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'json_data'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'block', 'children': ['36']},{'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': 'all_keys'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'all_keys'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '63']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '62'], 'value': '>'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'json_data'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted_json_data'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'json_data'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'binary_operator', 'children': ['80', '81'], 'value': '+'},{'id': '80', 'type': 'string', 'children': [], 'value': "'--> Sorted/cleaned '"},{'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': 'os'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'write_json'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted_json_data'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'filename'}
def sort_common_members(): filename = PREFIX + '/common_members.json' sorted_json_data = {} json_data = read_json(filename) all_keys = [] for key, value in json_data.items(): all_keys.append(key) sorted_keys = sorted(all_keys) for key in sorted_keys: if len(json_data[key]) > 0: sorted_json_data[key] = sorted(json_data[key]) print('--> Sorted/cleaned ' + os.path.basename(filename)) write_json(sorted_json_data, filename)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ConstructPartitions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection_links'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'partitions_per_node'},{'id': '7', 'type': 'block', 'children': ['8', '15', '33', '37', '92', '98']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'collections_node_count'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'collection_links'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'partitions'},{'id': '18', 'type': 'list_comprehension', 'children': ['19', '24']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_Partition'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '*'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'partitions_per_node'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'collections_node_count'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'collection_node'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'collection_links'},{'id': '40', 'type': 'block', 'children': ['41', '57']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'hash_value'},{'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': 'hash_generator'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ComputeHash'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_GetBytes'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'collection_node'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '64']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'partitions_per_node'},{'id': '64', 'type': 'block', 'children': ['65', '77', '81']},{'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': 'partitions'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_Partition'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'hash_value'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'collection_node'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'augmented_assignment', 'children': ['79', '80'], 'value': '+='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'hash_value'},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'hash_generator'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ComputeHash'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'hash_value'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'partitions'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'partitions'}
def _ConstructPartitions(self, collection_links, partitions_per_node): collections_node_count = len(collection_links) partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)] index = 0 for collection_node in collection_links: hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node)) for _ in xrange(0, partitions_per_node): partitions[index] = partition._Partition(hash_value, collection_node) index += 1 hash_value = self.hash_generator.ComputeHash(hash_value) partitions.sort() return partitions
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_leap_seconds'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '5', 'type': 'block', 'children': ['6', '13', '29', '38']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fileobj'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16', '21', '22']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '16', 'type': 'ERROR', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'break'},{'id': '21', 'type': 'block', 'children': [], 'value': ''},{'id': '22', 'type': 'else_clause', 'children': ['23']},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'Leap_Second.dat is missing its expiration date'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '38', 'type': 'with_statement', 'children': ['39', '42']},{'id': '39', 'type': 'with_clause', 'children': ['40']},{'id': '40', 'type': 'with_item', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_lock'},{'id': '42', 'type': 'block', 'children': ['43', '54', '64']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'original_locale'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'setlocale'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'LC_ALL'},{'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': 'locale'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'setlocale'},{'id': '59', 'type': 'argument_list', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'LC_ALL'},{'id': '63', 'type': 'string', 'children': [], 'value': "'C'"},{'id': '64', 'type': 'ERROR', 'children': ['65', '184']},{'id': '65', 'type': 'ERROR', 'children': ['66', '67', '70', '71', '82', '99', '101', '102', '103', '104', '181']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'ERROR', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'finally'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'setlocale'},{'id': '77', 'type': 'argument_list', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'LC_ALL'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'original_locale'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'grace_period'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '98'], 'value': '+'},{'id': '85', 'type': 'call', 'children': ['86', '97']},{'id': '86', 'type': 'attribute', 'children': ['87', '93', '96']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '92', 'type': 'integer', 'children': [], 'value': '30'},{'id': '93', 'type': 'ERROR', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'expiration_date'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'grace_period'},{'id': '99', 'type': 'ERROR', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mjd'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106', '180']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '106', 'type': 'ERROR', 'children': ['107', '132', '141', '149', '150', '151', '166', '169', '178', '179']},{'id': '107', 'type': 'subscript', 'children': ['108', '129', '131']},{'id': '108', 'type': 'call', 'children': ['109', '122']},{'id': '109', 'type': 'attribute', 'children': ['110', '118', '121']},{'id': '110', 'type': 'attribute', 'children': ['111', '117']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'loadtxt'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '118', 'type': 'ERROR', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'leap_dates'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '128'], 'value': '+'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'mjd'},{'id': '128', 'type': 'integer', 'children': [], 'value': '2'},{'id': '129', 'type': 'ERROR', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'leap_dates'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'subscript', 'children': ['133', '134', '136']},{'id': '133', 'type': 'string', 'children': [], 'value': "'-inf'"},{'id': '134', 'type': 'ERROR', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'leap_dates'},{'id': '136', 'type': 'slice', 'children': ['137', '138', '139']},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'colon', 'children': []},{'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mjd'},{'id': '143', 'type': 'subscript', 'children': ['144', '145', '147']},{'id': '144', 'type': 'float', 'children': [], 'value': '2400000.5'},{'id': '145', 'type': 'ERROR', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'leap_dates'},{'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '-'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'leap_offsets'},{'id': '151', 'type': 'subscript', 'children': ['152', '163', '165']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'binary_operator', 'children': ['158', '162'], 'value': '+'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'mjd'},{'id': '162', 'type': 'integer', 'children': [], 'value': '2'},{'id': '163', 'type': 'ERROR', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'leap_offsets'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'leap_offsets'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'subscript', 'children': ['170', '173', '175']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'ERROR', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'leap_offsets'},{'id': '175', 'type': 'slice', 'children': ['176', '177']},{'id': '176', 'type': 'integer', 'children': [], 'value': '2'},{'id': '177', 'type': 'colon', 'children': []},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'return'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'expiration_date'},{'id': '181', 'type': 'tuple', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'leap_dates'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'leap_offsets'},{'id': '184', 'type': 'block', 'children': [], 'value': ''}
def parse_leap_seconds(fileobj): lines = iter(fileobj) for line in lines: if line.startswith(b' break else: raise ValueError('Leap_Second.dat is missing its expiration date') line = line.decode('ascii') with _lock: original_locale = locale.setlocale(locale.LC_ALL) locale.setlocale(locale.LC_ALL, 'C') try: dt = datetime.strptime(line, ' finally: locale.setlocale(locale.LC_ALL, original_locale) grace_period = timedelta(days=30) expiration_date = dt.date() + grace_period mjd, day, month, year, offsets = np.loadtxt(lines).T leap_dates = np.ndarray(len(mjd) + 2) leap_dates[0] = '-inf' leap_dates[1:-1] = mjd + 2400000.5 leap_dates[-1] = 'inf' leap_offsets = np.ndarray(len(mjd) + 2) leap_offsets[0] = leap_offsets[1] = offsets[0] leap_offsets[2:] = offsets return expiration_date, (leap_dates, leap_offsets)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_delta_t_table'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'delta_t_recent'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '27', '37', '55', '62', '72', '80', '100', '104', '113', '126', '136', '150']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ancient'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'load_bundled_npy'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'morrison_stephenson_deltat.npy'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'historic'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'load_bundled_npy'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'historic_deltat.npy'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'historic_start_time'},{'id': '23', 'type': 'subscript', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'historic'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'i'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ancient'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'historic_start_time'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'bundled'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '42', 'type': 'argument_list', 'children': ['43', '52']},{'id': '43', 'type': 'list', 'children': ['44', '51'], 'value': '[ancient[:,:i], historic]'},{'id': '44', 'type': 'subscript', 'children': ['45', '46', '48']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ancient'},{'id': '46', 'type': 'slice', 'children': ['47']},{'id': '47', 'type': 'colon', 'children': []},{'id': '48', 'type': 'slice', 'children': ['49', '50']},{'id': '49', 'type': 'colon', 'children': []},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'historic'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'recent_start_time'},{'id': '58', 'type': 'subscript', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'delta_t_recent'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'bundled'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'recent_start_time'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '75', 'type': 'tuple', 'children': ['76', '78']},{'id': '76', 'type': 'tuple', 'children': ['77']},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'tuple', 'children': ['79']},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '85', 'type': 'argument_list', 'children': ['86', '97']},{'id': '86', 'type': 'list', 'children': ['87', '88', '95', '96'], 'value': '[row, bundled[:,:i], delta_t_recent, row]'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '88', 'type': 'subscript', 'children': ['89', '90', '92']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'bundled'},{'id': '90', 'type': 'slice', 'children': ['91']},{'id': '91', 'type': 'colon', 'children': []},{'id': '92', 'type': 'slice', 'children': ['93', '94']},{'id': '93', 'type': 'colon', 'children': []},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'delta_t_recent'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'century'},{'id': '103', 'type': 'float', 'children': [], 'value': '36524.0'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'binary_operator', 'children': ['108', '112'], 'value': '-'},{'id': '108', 'type': 'subscript', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'century'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '120']},{'id': '115', 'type': 'subscript', 'children': ['116', '117', '119']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '117', 'type': 'slice', 'children': ['118']},{'id': '118', 'type': 'colon', 'children': []},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'expression_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'delta_t_formula_morrison_and_stephenson_2004'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '135'], 'value': '+'},{'id': '130', 'type': 'subscript', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'unary_operator', 'children': ['134'], 'value': '-'},{'id': '134', 'type': 'integer', 'children': [], 'value': '2'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'century'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '144']},{'id': '138', 'type': 'subscript', 'children': ['139', '140', '142']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '140', 'type': 'slice', 'children': ['141']},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'unary_operator', 'children': ['143'], 'value': '-'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'expression_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'delta_t_formula_morrison_and_stephenson_2004'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'table'}
def build_delta_t_table(delta_t_recent): ancient = load_bundled_npy('morrison_stephenson_deltat.npy') historic = load_bundled_npy('historic_deltat.npy') historic_start_time = historic[0,0] i = searchsorted(ancient[0], historic_start_time) bundled = concatenate([ancient[:,:i], historic], axis=1) recent_start_time = delta_t_recent[0,0] i = searchsorted(bundled[0], recent_start_time) row = ((0,),(0,)) table = concatenate([row, bundled[:,:i], delta_t_recent, row], axis=1) century = 36524.0 start = table[0,1] - century table[:,0] = start, delta_t_formula_morrison_and_stephenson_2004(start) end = table[0,-2] + century table[:,-1] = end, delta_t_formula_morrison_and_stephenson_2004(end) return table
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '55']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_confusion_matrix_with_cv'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37', '40', '43', '46', '49', '52']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'hide_zeros'},{'id': '24', 'type': 'False', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x_tick_rotation'},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'do_cv'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'default_parameter', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'default_parameter', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'default_parameter', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'default_parameter', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '48', 'type': 'string', 'children': [], 'value': "'Blues'"},{'id': '49', 'type': 'default_parameter', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '51', 'type': 'string', 'children': [], 'value': '"large"'},{'id': '52', 'type': 'default_parameter', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '54', 'type': 'string', 'children': [], 'value': '"medium"'},{'id': '55', 'type': 'block', 'children': ['56', '65', '226', '276']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'y'},{'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': 'array'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '65', 'type': 'if_statement', 'children': ['66', '68', '82']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'do_cv'},{'id': '68', 'type': 'block', 'children': ['69', '78']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '126', '133', '137', '141', '208', '217']},{'id': '84', 'type': 'if_statement', 'children': ['85', '88', '101', '123']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '87', 'type': 'None', 'children': []},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'StratifiedKFold'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '101', 'type': 'elif_clause', 'children': ['102', '107']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'StratifiedKFold'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117', '120']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'n_splits'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'pass_statement', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'clf_clone'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'clone'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'clf'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'preds_list'},{'id': '136', 'type': 'list', 'children': [], 'value': '[]'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'trues_list'},{'id': '140', 'type': 'list', 'children': [], 'value': '[]'},{'id': '141', 'type': 'for_statement', 'children': ['142', '145', '152']},{'id': '142', 'type': 'pattern_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'train_index'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'test_index'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'cv'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '152', 'type': 'block', 'children': ['153', '165', '177', '185', '194', '201']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'pattern_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '158', 'type': 'expression_list', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'train_index'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'test_index'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'pattern_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'y_test'},{'id': '170', 'type': 'expression_list', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'train_index'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'test_index'},{'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': 'clf_clone'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'X_train'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'y_train'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'preds'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'clf_clone'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'X_test'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'preds_list'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'preds'},{'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': 'trues_list'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'y_test'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'preds_list'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'concatenate'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'trues_list'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'plotters'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'plot_confusion_matrix'},{'id': '233', 'type': 'argument_list', 'children': ['234', '237', '240', '243', '246', '249', '252', '255', '258', '261', '264', '267', '270', '273']},{'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '237', 'type': 'keyword_argument', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '249', 'type': 'keyword_argument', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'hide_zeros'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'hide_zeros'},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'x_tick_rotation'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'x_tick_rotation'},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'ax'}
def plot_confusion_matrix_with_cv(clf, X, y, labels=None, true_labels=None, pred_labels=None, title=None, normalize=False, hide_zeros=False, x_tick_rotation=0, do_cv=True, cv=None, shuffle=True, random_state=None, ax=None, figsize=None, cmap='Blues', title_fontsize="large", text_fontsize="medium"): y = np.array(y) if not do_cv: y_pred = clf.predict(X) y_true = y else: if cv is None: cv = StratifiedKFold(shuffle=shuffle, random_state=random_state) elif isinstance(cv, int): cv = StratifiedKFold(n_splits=cv, shuffle=shuffle, random_state=random_state) else: pass clf_clone = clone(clf) preds_list = [] trues_list = [] for train_index, test_index in cv.split(X, y): X_train, X_test = X[train_index], X[test_index] y_train, y_test = y[train_index], y[test_index] clf_clone.fit(X_train, y_train) preds = clf_clone.predict(X_test) preds_list.append(preds) trues_list.append(y_test) y_pred = np.concatenate(preds_list) y_true = np.concatenate(trues_list) ax = plotters.plot_confusion_matrix(y_true=y_true, y_pred=y_pred, labels=labels, true_labels=true_labels, pred_labels=pred_labels, title=title, normalize=normalize, hide_zeros=hide_zeros, x_tick_rotation=x_tick_rotation, ax=ax, figsize=figsize, cmap=cmap, title_fontsize=title_fontsize, text_fontsize=text_fontsize) return ax
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '42']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_confusion_matrix'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'hide_zeros'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x_tick_rotation'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '35', 'type': 'string', 'children': [], 'value': "'Blues'"},{'id': '36', 'type': 'default_parameter', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '38', 'type': 'string', 'children': [], 'value': '"large"'},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '41', 'type': 'string', 'children': [], 'value': '"medium"'},{'id': '42', 'type': 'block', 'children': ['43', '63', '74', '98', '148', '188', '230', '268', '290', '299', '311', '323', '330', '343', '350', '360', '370', '440', '450', '460', '467']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ax'},{'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': 'subplots'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60']},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'figsize'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'confusion_matrix'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '74', 'type': 'if_statement', 'children': ['75', '78', '87']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'unique_labels'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'y_true'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'y_pred'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '100', 'type': 'block', 'children': ['101', '125', '137']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '104', 'type': 'binary_operator', 'children': ['105', '111'], 'value': '/'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'float'"},{'id': '111', 'type': 'subscript', 'children': ['112', '120', '122']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'slice', 'children': ['121']},{'id': '121', 'type': 'colon', 'children': []},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'newaxis'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'around'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'decimals'},{'id': '136', 'type': 'integer', 'children': [], 'value': '2'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '147']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '147', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '148', 'type': 'if_statement', 'children': ['149', '152', '157']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'true_classes'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159', '166', '176', '182']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'validate_labels'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164', '165']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '165', 'type': 'string', 'children': [], 'value': '"true_labels"'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'true_label_indexes'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'true_labels'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'true_classes'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'true_label_indexes'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'true_label_indexes'},{'id': '188', 'type': 'if_statement', 'children': ['189', '192', '197']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '191', 'type': 'None', 'children': []},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'pred_classes'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '197', 'type': 'else_clause', 'children': ['198']},{'id': '198', 'type': 'block', 'children': ['199', '206', '216', '222']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'validate_labels'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '205', 'type': 'string', 'children': [], 'value': '"pred_labels"'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'pred_label_indexes'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'pred_labels'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'pred_classes'},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'pred_label_indexes'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '225', 'type': 'subscript', 'children': ['226', '227', '229']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '227', 'type': 'slice', 'children': ['228']},{'id': '228', 'type': 'colon', 'children': []},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'pred_label_indexes'},{'id': '230', 'type': 'if_statement', 'children': ['231', '232', '243', '256']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'title'},{'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': 'ax'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'set_title'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '243', 'type': 'elif_clause', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'set_title'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': "'Normalized Confusion Matrix'"},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '256', 'type': 'else_clause', 'children': ['257']},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'set_title'},{'id': '263', 'type': 'argument_list', 'children': ['264', '265']},{'id': '264', 'type': 'string', 'children': [], 'value': "'Confusion Matrix'"},{'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'title_fontsize'},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'imshow'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277', '280']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'interpolation'},{'id': '279', 'type': 'string', 'children': [], 'value': "'nearest'"},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '282', 'type': 'call', 'children': ['283', '288']},{'id': '283', 'type': 'attribute', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'get_cmap'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'colorbar'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'mappable'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'x_tick_marks'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'pred_classes'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'y_tick_marks'},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'true_classes'},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'set_xticks'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'x_tick_marks'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'set_xticklabels'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337', '340']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'pred_classes'},{'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'rotation'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'x_tick_rotation'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'set_yticks'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'y_tick_marks'},{'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': 'ax'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'set_yticklabels'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'true_classes'},{'id': '357', 'type': 'keyword_argument', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'assignment', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '363', 'type': 'binary_operator', 'children': ['364', '369'], 'value': '/'},{'id': '364', 'type': 'call', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '368', 'type': 'argument_list', 'children': []},{'id': '369', 'type': 'float', 'children': [], 'value': '2.'},{'id': '370', 'type': 'for_statement', 'children': ['371', '374', '395']},{'id': '371', 'type': 'pattern_list', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '378', 'type': 'argument_list', 'children': ['379', '387']},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'subscript', 'children': ['383', '386']},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '386', 'type': 'integer', 'children': [], 'value': '0'},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'subscript', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '394', 'type': 'integer', 'children': [], 'value': '1'},{'id': '395', 'type': 'block', 'children': ['396']},{'id': '396', 'type': 'if_statement', 'children': ['397', '407']},{'id': '397', 'type': 'not_operator', 'children': ['398']},{'id': '398', 'type': '()', 'children': ['399']},{'id': '399', 'type': 'boolean_operator', 'children': ['400', '401'], 'value': 'and'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'hide_zeros'},{'id': '401', 'type': 'comparison_operator', 'children': ['402', '406'], 'value': '=='},{'id': '402', 'type': 'subscript', 'children': ['403', '404', '405']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '406', 'type': 'integer', 'children': [], 'value': '0'},{'id': '407', 'type': 'block', 'children': ['408']},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '413']},{'id': '410', 'type': 'attribute', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '413', 'type': 'argument_list', 'children': ['414', '415', '416', '420', '423', '426', '429']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '416', 'type': 'subscript', 'children': ['417', '418', '419']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '420', 'type': 'keyword_argument', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'horizontalalignment'},{'id': '422', 'type': 'string', 'children': [], 'value': '"center"'},{'id': '423', 'type': 'keyword_argument', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'verticalalignment'},{'id': '425', 'type': 'string', 'children': [], 'value': '"center"'},{'id': '426', 'type': 'keyword_argument', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '429', 'type': 'keyword_argument', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '431', 'type': 'conditional_expression', 'children': ['432', '433', '439'], 'value': 'if'},{'id': '432', 'type': 'string', 'children': [], 'value': '"white"'},{'id': '433', 'type': 'comparison_operator', 'children': ['434', '438'], 'value': '>'},{'id': '434', 'type': 'subscript', 'children': ['435', '436', '437']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '439', 'type': 'string', 'children': [], 'value': '"black"'},{'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': 'ax'},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'},{'id': '445', 'type': 'argument_list', 'children': ['446', '447']},{'id': '446', 'type': 'string', 'children': [], 'value': "'True label'"},{'id': '447', 'type': 'keyword_argument', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '450', 'type': 'expression_statement', 'children': ['451']},{'id': '451', 'type': 'call', 'children': ['452', '455']},{'id': '452', 'type': 'attribute', 'children': ['453', '454']},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'},{'id': '455', 'type': 'argument_list', 'children': ['456', '457']},{'id': '456', 'type': 'string', 'children': [], 'value': "'Predicted label'"},{'id': '457', 'type': 'keyword_argument', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'fontsize'},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'text_fontsize'},{'id': '460', 'type': 'expression_statement', 'children': ['461']},{'id': '461', 'type': 'call', 'children': ['462', '465']},{'id': '462', 'type': 'attribute', 'children': ['463', '464']},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '464', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '465', 'type': 'argument_list', 'children': ['466']},{'id': '466', 'type': 'string', 'children': [], 'value': "'off'"},{'id': '467', 'type': 'return_statement', 'children': ['468']},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'ax'}
def plot_confusion_matrix(y_true, y_pred, labels=None, true_labels=None, pred_labels=None, title=None, normalize=False, hide_zeros=False, x_tick_rotation=0, ax=None, figsize=None, cmap='Blues', title_fontsize="large", text_fontsize="medium"): if ax is None: fig, ax = plt.subplots(1, 1, figsize=figsize) cm = confusion_matrix(y_true, y_pred, labels=labels) if labels is None: classes = unique_labels(y_true, y_pred) else: classes = np.asarray(labels) if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] cm = np.around(cm, decimals=2) cm[np.isnan(cm)] = 0.0 if true_labels is None: true_classes = classes else: validate_labels(classes, true_labels, "true_labels") true_label_indexes = np.in1d(classes, true_labels) true_classes = classes[true_label_indexes] cm = cm[true_label_indexes] if pred_labels is None: pred_classes = classes else: validate_labels(classes, pred_labels, "pred_labels") pred_label_indexes = np.in1d(classes, pred_labels) pred_classes = classes[pred_label_indexes] cm = cm[:, pred_label_indexes] if title: ax.set_title(title, fontsize=title_fontsize) elif normalize: ax.set_title('Normalized Confusion Matrix', fontsize=title_fontsize) else: ax.set_title('Confusion Matrix', fontsize=title_fontsize) image = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.get_cmap(cmap)) plt.colorbar(mappable=image) x_tick_marks = np.arange(len(pred_classes)) y_tick_marks = np.arange(len(true_classes)) ax.set_xticks(x_tick_marks) ax.set_xticklabels(pred_classes, fontsize=text_fontsize, rotation=x_tick_rotation) ax.set_yticks(y_tick_marks) ax.set_yticklabels(true_classes, fontsize=text_fontsize) thresh = cm.max() / 2. for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): if not (hide_zeros and cm[i, j] == 0): ax.text(j, i, cm[i, j], horizontalalignment="center", verticalalignment="center", fontsize=text_fontsize, color="white" if cm[i, j] > thresh else "black") ax.set_ylabel('True label', fontsize=text_fontsize) ax.set_xlabel('Predicted label', fontsize=text_fontsize) ax.grid('off') return ax
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorting'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '124']},{'id': '6', 'type': 'if_statement', 'children': ['7', '15']},{'id': '7', 'type': 'call', 'children': ['8', '13']},{'id': '8', 'type': 'attribute', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '15', 'type': 'block', 'children': ['16', '20', '122']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorting_results'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '32']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '22', 'type': 'call', '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': 'qs'},{'id': '28', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "','"},{'id': '32', 'type': 'block', 'children': ['33', '43', '67', '87', '97', '109']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '42', 'type': 'string', 'children': [], 'value': "''"},{'id': '43', 'type': 'if_statement', 'children': ['44', '51']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'not'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'schema'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_declared_fields'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'raise_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'InvalidSort'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"{} has no attribute {}"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', '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': 'schema'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '67', 'type': 'if_statement', 'children': ['68', '76']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_relationships'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'raise_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'InvalidSort'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': '"You can\'t sort on {} because it is a relationship field"'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_model_field'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '100', 'type': 'conditional_expression', 'children': ['101', '102', '108'], 'value': 'if'},{'id': '101', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'sorting_results'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'dictionary', 'children': ['116', '119']},{'id': '116', 'type': 'pair', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': "'field'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '119', 'type': 'pair', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sorting_results'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'}
def sorting(self): if self.qs.get('sort'): sorting_results = [] for sort_field in self.qs['sort'].split(','): field = sort_field.replace('-', '') if field not in self.schema._declared_fields: raise InvalidSort("{} has no attribute {}".format(self.schema.__name__, field)) if field in get_relationships(self.schema): raise InvalidSort("You can't sort on {} because it is a relationship field".format(field)) field = get_model_field(self.schema, field) order = 'desc' if sort_field.startswith('-') else 'asc' sorting_results.append({'field': field, 'order': order}) return sorting_results return []
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter_info'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '8', 'type': 'block', 'children': ['9', '33']},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'filter_info'},{'id': '11', 'type': 'block', 'children': ['12', '23']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'create_filters'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'filter_info'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'list_splat', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'query'}
def filter_query(self, query, filter_info, model): if filter_info: filters = create_filters(model, filter_info, self.resource) query = query.filter(*filters) return query
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_info'},{'id': '7', 'type': 'block', 'children': ['8', '66']},{'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_info'},{'id': '11', 'type': 'block', 'children': ['12', '18', '43']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '17', 'type': 'string', 'children': [], 'value': "'field'"},{'id': '18', 'type': 'if_statement', 'children': ['19', '27']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '22', 'type': 'argument_list', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'InvalidSort'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': '"{} has no attribute {}"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '36', 'type': 'argument_list', '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': 'model'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '65']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '54', 'type': 'argument_list', 'children': ['55', '62']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort_opt'},{'id': '64', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'query'}
def sort_query(self, query, sort_info): for sort_opt in sort_info: field = sort_opt['field'] if not hasattr(self.model, field): raise InvalidSort("{} has no attribute {}".format(self.model.__name__, field)) query = query.order_by(getattr(getattr(self.model, field), sort_opt['order'])()) return query
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_log_entries'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '8', 'type': 'type_parameter', 'children': ['9']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'generic_type', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '12', 'type': 'type_parameter', 'children': ['13', '15', '17', '23']},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'generic_type', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '20', 'type': 'type_parameter', 'children': ['21']},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '23', 'type': 'type', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '33']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'is_error'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_log_entries'},{'id': '47', 'type': 'list_splat', 'children': ['48']},{'id': '48', 'type': 'generator_expression', 'children': ['49', '54']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_get_log_entries'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'children'}
def _get_log_entries(self) -> List[Tuple[int, bytes, List[int], bytes]]: if self.is_error: return [] else: return sorted(itertools.chain( self._log_entries, *(child._get_log_entries() for child in self.children) ))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_size'},{'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': 'group_limit'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'discard_others'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '13', 'type': 'string', 'children': [], 'value': "'others'"},{'id': '14', 'type': 'block', 'children': ['15', '48', '155']},{'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': 'groups'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26', '34', '45']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'lambda', 'children': ['37', '39']},{'id': '37', 'type': 'lambda_parameters', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '47', 'type': 'True', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'group_limit'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'block', 'children': ['53', '101', '130']},{'id': '53', 'type': 'if_statement', 'children': ['54', '56', '85']},{'id': '54', 'type': 'not_operator', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'discard_others'},{'id': '56', 'type': 'block', 'children': ['57', '73']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '60', 'type': 'subscript', 'children': ['61', '68']},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'slice', 'children': ['69', '72']},{'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '-'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'group_limit'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'colon', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '90', 'type': 'subscript', 'children': ['91', '98']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'slice', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'group_limit'},{'id': '100', 'type': 'colon', 'children': []},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'group_keys'},{'id': '104', 'type': 'block', 'children': ['105', '124']},{'id': '105', 'type': 'if_statement', 'children': ['106', '108']},{'id': '106', 'type': 'not_operator', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'discard_others'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '118']},{'id': '111', 'type': 'attribute', 'children': ['112', '117']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '124', 'type': 'delete_statement', 'children': ['125']},{'id': '125', 'type': 'subscript', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '130', 'type': 'if_statement', 'children': ['131', '148']},{'id': '131', 'type': '()', 'children': ['132']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '138'], 'value': 'and'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '147'], 'value': '=='},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'delete_statement', 'children': ['150']},{'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': 'groups'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '155', 'type': 'if_statement', 'children': ['156', '163']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '158'], 'value': 'and'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'discard_others'},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'in'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'others_label'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'delete_statement', 'children': ['165']},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'others_label'}
def sort_by_size(self, group_limit=None, discard_others=False, others_label='others'): self.groups = OrderedDict(sorted(six.iteritems(self.groups), key=lambda x: len(x[1]), reverse=True)) if group_limit is not None: if not discard_others: group_keys = self.groups.keys()[group_limit - 1:] self.groups.setdefault(others_label, list()) else: group_keys = self.groups.keys()[group_limit:] for g in group_keys: if not discard_others: self.groups[others_label].extend(self.groups[g]) del self.groups[g] if (others_label in self.groups and len(self.groups[others_label]) == 0): del self.groups[others_label] if discard_others and others_label in self.groups: del self.groups[others_label]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_comments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '27', '67']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '15', 'type': 'argument_list', 'children': ['16', '21', '24']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'apikey'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '27', 'type': 'try_statement', 'children': ['28', '50']},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '36', 'type': 'argument_list', 'children': ['37', '42', '45']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '41'], 'value': '+'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '41', 'type': 'string', 'children': [], 'value': "'comments/get'"},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '50', 'type': 'except_clause', 'children': ['51', '57']},{'id': '51', 'type': 'as_pattern', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '55', 'type': 'as_pattern_target', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_return_response_and_status_code'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'response'}
def get_comments(self, resource, before=None): params = dict(apikey=self.api_key, resource=resource, before=before) try: response = requests.get(self.base + 'comments/get', params=params, proxies=self.proxies) except requests.RequestException as e: return dict(error=e.message) return _return_response_and_status_code(response)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_fail'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '5', 'type': 'block', 'children': ['6', '8', '56']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n A decorator to cleanly exit on a failed call to AWS.\n catch a `botocore.exceptions.ClientError` raised from an action.\n This sort of error is raised if you are targeting a region that\n isn't set up (see, `credstash setup`.\n '''"},{'id': '8', 'type': 'function_definition', 'children': ['9', '10', '15']},{'id': '9', 'type': 'function_name', 'children': [], 'value': 'func_wrapper'},{'id': '10', 'type': 'parameters', 'children': ['11', '13']},{'id': '11', 'type': 'list_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'try_statement', 'children': ['17', '26']},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '21', 'type': 'argument_list', 'children': ['22', '24']},{'id': '22', 'type': 'list_splat', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '24', 'type': 'dictionary_splat', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '26', 'type': 'except_clause', 'children': ['27', '35']},{'id': '27', 'type': 'as_pattern', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'botocore'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '33', 'type': 'as_pattern_target', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '35', 'type': 'block', 'children': ['36', '49']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '39', 'type': 'argument_list', 'children': ['40', '44']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'func_wrapper'}
def clean_fail(func): ''' A decorator to cleanly exit on a failed call to AWS. catch a `botocore.exceptions.ClientError` raised from an action. This sort of error is raised if you are targeting a region that isn't set up (see, `credstash setup`. ''' def func_wrapper(*args, **kwargs): try: return func(*args, **kwargs) except botocore.exceptions.ClientError as e: print(str(e), file=sys.stderr) sys.exit(1) return func_wrapper
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_header'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'string', 'children': [], 'value': "'*/*'"},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'yield', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '13', 'type': 'argument_list', 'children': ['14', '39']},{'id': '14', 'type': 'generator_expression', 'children': ['15', '25', '33']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'from_string'},{'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': 'token'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "','"},{'id': '33', 'type': 'if_clause', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '41', 'type': 'True', 'children': []}
def parse_header(cls, value='*/*'): yield from sorted(( cls.from_string(token.strip()) for token in value.split(',') if token.strip() ), reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_canonical'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '6', 'type': 'block', 'children': ['7', '22', '26', '39', '105', '120']},{'id': '7', 'type': 'try_statement', 'children': ['8', '17']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '14']},{'id': '11', 'type': 'tuple_pattern', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_arg_type'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'subspec'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stmt_map'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '17', 'type': 'except_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '37'], 'value': '+'},{'id': '30', 'type': 'list_comprehension', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data_def_stmts'},{'id': '37', 'type': 'list', 'children': ['38'], 'value': "['case']"},{'id': '38', 'type': 'string', 'children': [], 'value': "'case'"},{'id': '39', 'type': 'for_statement', 'children': ['40', '43', '47']},{'id': '40', 'type': 'tuple_pattern', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_spec'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'flatten_spec'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'subspec'},{'id': '47', 'type': 'block', 'children': ['48', '52']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '62', '70', '99']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '61', 'type': 'string', 'children': [], 'value': "'_comment'"},{'id': '62', 'type': 'block', 'children': ['63']},{'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': 'comments'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '70', 'type': 'elif_clause', 'children': ['71', '80']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '77'], 'value': 'and'},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': '=='},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'keep'},{'id': '80', 'type': 'block', 'children': ['81', '88', '92']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '104', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'res'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '113', '116']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '116', 'type': 'if_clause', 'children': ['117']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'not'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'res'}
def sort_canonical(keyword, stmts): try: (_arg_type, subspec) = stmt_map[keyword] except KeyError: return stmts res = [] keep = [s[0] for s in data_def_stmts] + ['case'] for (kw, _spec) in flatten_spec(subspec): comments = [] for s in stmts: if s.keyword == '_comment': comments.append(s) elif s.keyword == kw and kw not in keep: res.extend(comments) comments = [] res.append(s) else: comments = [] res.extend([stmt for stmt in stmts if stmt not in res]) return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '33', '58', '63', '82', '112', '158', '168', '178', '197', '225', '238']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '\'\'\'Sort and return the list, set or sorted set at ``key``.\n ``start`` and ``num`` allow for paging through the sorted data\n ``by`` allows using an external key to weight and sort the items.\n Use an "*" to indicate where in the key the item value is located\n ``get`` allows for returning items from external keys rather than the\n sorted data itself. Use an "*" to indicate where int he key\n the item value is located\n ``desc`` allows for reversing the sort\n ``alpha`` allows for sorting lexicographically rather than numerically\n ``store`` allows for storing the result of the sort into\n the key ``store``\n ``groups`` if set to True and if ``get`` contains at least two\n elements, sort will return a list of tuples, each containing the\n values fetched from the arguments to ``get``.\n \'\'\''},{'id': '33', 'type': 'if_statement', 'children': ['34', '52']},{'id': '34', 'type': '()', 'children': ['35']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '44'], 'value': 'or'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': 'is'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': '()', 'children': ['45']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'raise_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'CommandError'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"``start`` and ``num`` must both be specified"'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '61', 'type': 'list', 'children': ['62'], 'value': '[key]'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'block', 'children': ['68', '75']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'BY'"},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '82', 'type': 'if_statement', 'children': ['83', '90']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '87'], 'value': 'and'},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'block', 'children': ['91', '98', '105']},{'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': 'pieces'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'string', 'children': [], 'value': "'LIMIT'"},{'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': 'pieces'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'start'},{'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': 'pieces'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'if_statement', 'children': ['118', '123', '138']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '123', 'type': 'block', 'children': ['124', '131']},{'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': 'pieces'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '138', 'type': 'else_clause', 'children': ['139']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '143', 'type': 'block', 'children': ['144', '151']},{'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': 'pieces'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'string', 'children': [], 'value': "'GET'"},{'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': 'pieces'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '158', 'type': 'if_statement', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'DESC'"},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'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': 'pieces'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'string', 'children': [], 'value': "'ALPHA'"},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'is'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '181', 'type': 'None', 'children': []},{'id': '182', 'type': 'block', 'children': ['183', '190']},{'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': 'pieces'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'string', 'children': [], 'value': "'STORE'"},{'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': 'pieces'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '197', 'type': 'if_statement', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'if_statement', 'children': ['201', '216']},{'id': '201', 'type': 'boolean_operator', 'children': ['202', '210'], 'value': 'or'},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '205'], 'value': 'or'},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '215'], 'value': '<'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '215', 'type': 'integer', 'children': [], 'value': '2'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'raise_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'CommandError'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'concatenated_string', 'children': ['222', '223', '224']},{'id': '222', 'type': 'string', 'children': [], 'value': '\'when using "groups" the "get" argument \''},{'id': '223', 'type': 'string', 'children': [], 'value': "'must be specified and contain at least '"},{'id': '224', 'type': 'string', 'children': [], 'value': "'two keys'"},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '228', 'type': 'dictionary', 'children': ['229']},{'id': '229', 'type': 'pair', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': "'groups'"},{'id': '231', 'type': 'conditional_expression', 'children': ['232', '236', '237'], 'value': 'if'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '237', 'type': 'None', 'children': []},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'execute_command'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245', '247']},{'id': '244', 'type': 'string', 'children': [], 'value': "'SORT'"},{'id': '245', 'type': 'list_splat', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'pieces'},{'id': '247', 'type': 'dictionary_splat', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'options'}
def sort(self, key, start=None, num=None, by=None, get=None, desc=False, alpha=False, store=None, groups=False): '''Sort and return the list, set or sorted set at ``key``. ``start`` and ``num`` allow for paging through the sorted data ``by`` allows using an external key to weight and sort the items. Use an "*" to indicate where in the key the item value is located ``get`` allows for returning items from external keys rather than the sorted data itself. Use an "*" to indicate where int he key the item value is located ``desc`` allows for reversing the sort ``alpha`` allows for sorting lexicographically rather than numerically ``store`` allows for storing the result of the sort into the key ``store`` ``groups`` if set to True and if ``get`` contains at least two elements, sort will return a list of tuples, each containing the values fetched from the arguments to ``get``. ''' if ((start is not None and num is None) or (num is not None and start is None)): raise CommandError("``start`` and ``num`` must both be specified") pieces = [key] if by is not None: pieces.append('BY') pieces.append(by) if start is not None and num is not None: pieces.append('LIMIT') pieces.append(start) pieces.append(num) if get is not None: if isinstance(get, str): pieces.append('GET') pieces.append(get) else: for g in get: pieces.append('GET') pieces.append(g) if desc: pieces.append('DESC') if alpha: pieces.append('ALPHA') if store is not None: pieces.append('STORE') pieces.append(store) if groups: if not get or isinstance(get, str) or len(get) < 2: raise CommandError('when using "groups" the "get" argument ' 'must be specified and contain at least ' 'two keys') options = {'groups': len(get) if groups else None} return self.execute_command('SORT', *pieces, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_url_filemeta'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'block', 'children': ['6', '13', '20', '35', '43', '127']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'try_parse_url'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '29']},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'ftp'"},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_ftp_filemeta'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'geturl'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'try_statement', 'children': ['44', '113', '118']},{'id': '44', 'type': 'block', 'children': ['45', '63', '76']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '57', '60']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '56', 'type': 'True', 'children': []},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'allow_redirects'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '62', 'type': 'integer', 'children': [], 'value': '5'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'remote_size'},{'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': 'r'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'Content-Length'"},{'id': '74', 'type': 'unary_operator', 'children': ['75'], 'value': '-'},{'id': '75', 'type': 'integer', 'children': [], 'value': '1'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '79', 'type': 'argument_list', 'children': ['80', '83', '88', '93', '98', '101']},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'remote_size'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'remote_size'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '113', 'type': 'except_clause', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'except_clause', 'children': ['119', '124']},{'id': '119', 'type': 'tuple', 'children': ['120', '121', '122', '123']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'InvalidURL'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'InvalidSchema'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'InvalidHeader'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'MissingSchema'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'None', 'children': []}
def get_url_filemeta(url): parsed_url = try_parse_url(url) if parsed_url is None: return None if parsed_url.scheme.startswith('ftp'): return get_ftp_filemeta(parsed_url) url = parsed_url.geturl() try: r = requests.get(url, stream=True, allow_redirects=True, timeout=5) remote_size = r.headers.get('Content-Length', -1) return dict(url=url, hostname=parsed_url.hostname, path=parsed_url.path, username=parsed_url.username, remote_size=remote_size, filename=os.path.basename(parsed_url.path)) except ConnectionError: return None except (InvalidURL, InvalidSchema, InvalidHeader, MissingSchema): return None return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '59']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'offline_plotly_scatter_bubble'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '32', '35', '38', '50', '56']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '7', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '10', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '13', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'text_col'},{'id': '16', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '19', 'type': 'string', 'children': [], 'value': "'category'"},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '28', 'type': 'dictionary', 'children': ['29']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'displaylogo'"},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'xscale'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'yscale'},{'id': '37', 'type': 'string', 'children': [], 'value': "'log'"},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '40', 'type': 'dictionary', 'children': ['41', '44', '47']},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'hovermode'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'closest'"},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'showlegend'"},{'id': '46', 'type': 'False', 'children': []},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'autosize'"},{'id': '49', 'type': 'True', 'children': []},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '52', 'type': 'dictionary', 'children': ['53']},{'id': '53', 'type': 'pair', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "'sizemode'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'area'"},{'id': '56', 'type': 'default_parameter', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'min_size'},{'id': '58', 'type': 'integer', 'children': [], 'value': '10'},{'id': '59', 'type': 'block', 'children': ['60', '62', '69', '98', '105', '114', '140', '148', '160', '171', '214', '224', '271', '354']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'config_default'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_PLOTLY_CONFIG'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'marker_default'},{'id': '72', 'type': 'dictionary', 'children': ['73', '78', '81']},{'id': '73', 'type': 'pair', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'or'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'min_size'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'sizemode'"},{'id': '80', 'type': 'string', 'children': [], 'value': "'area'"},{'id': '81', 'type': 'pair', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'sizeref'"},{'id': '83', 'type': 'conditional_expression', 'children': ['84', '96', '97'], 'value': 'if'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'binary_operator', 'children': ['88', '95'], 'value': '*'},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'float', 'children': [], 'value': '.8'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'min_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': 'marker_default'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'marker_default'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'layout_default'},{'id': '117', 'type': 'dictionary', 'children': ['118', '129']},{'id': '118', 'type': 'pair', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'xaxis'"},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'XAxis'},{'id': '122', 'type': 'argument_list', 'children': ['123', '126']},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'xscale'},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'yaxis'"},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'YAxis'},{'id': '133', 'type': 'argument_list', 'children': ['134', '137']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'yscale'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'layout_default'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'dictionary_splat', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '148', 'type': 'if_statement', 'children': ['149', '152']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '151', 'type': 'None', 'children': []},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'config_default'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'clean_columns'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '171', 'type': 'if_statement', 'children': ['172', '179']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '176'], 'value': 'and'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'is'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '175', 'type': 'None', 'children': []},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'is'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '178', 'type': 'None', 'children': []},{'id': '179', 'type': 'block', 'children': ['180', '204']},{'id': '180', 'type': 'if_statement', 'children': ['181', '186', '193']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'in'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'category_labels'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'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': 'category_labels'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'category_labels'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '217', 'type': 'conditional_expression', 'children': ['218', '220', '223'], 'value': 'if'},{'id': '218', 'type': 'list', 'children': ['219'], 'value': '[None]'},{'id': '219', 'type': 'None', 'children': []},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'is'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '222', 'type': 'None', 'children': []},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '224', 'type': 'if_statement', 'children': ['225', '230', '248']},{'id': '225', 'type': 'boolean_operator', 'children': ['226', '227'], 'value': 'and'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'in'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'masks'},{'id': '234', 'type': 'list_comprehension', 'children': ['235', '245']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '244'], 'value': '=='},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'category_col'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '245', 'type': 'for_in_clause', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '248', 'type': 'else_clause', 'children': ['249']},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'masks'},{'id': '253', 'type': 'binary_operator', 'children': ['254', '267'], 'value': '*'},{'id': '254', 'type': 'list', 'children': ['255'], 'value': '[np.array([True] * len(df))]'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '263'], 'value': '*'},{'id': '261', 'type': 'list', 'children': ['262'], 'value': '[True]'},{'id': '262', 'type': 'True', 'children': []},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '274', 'type': 'dictionary', 'children': ['275', '347']},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '277', 'type': 'list_comprehension', 'children': ['278', '338']},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'Scatter'},{'id': '280', 'type': 'argument_list', 'children': ['281', '290', '299', '308', '329', '332']},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '283', 'type': 'attribute', 'children': ['284', '289']},{'id': '284', 'type': 'subscript', 'children': ['285', '288']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '292', 'type': 'attribute', 'children': ['293', '298']},{'id': '293', 'type': 'subscript', 'children': ['294', '297']},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '301', 'type': 'attribute', 'children': ['302', '307']},{'id': '302', 'type': 'subscript', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'text_col'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'Marker'},{'id': '312', 'type': 'argument_list', 'children': ['313', '327']},{'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '315', 'type': 'conditional_expression', 'children': ['316', '321', '326'], 'value': 'if'},{'id': '316', 'type': 'subscript', 'children': ['317', '320']},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': 'in'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'size_col'},{'id': '327', 'type': 'dictionary_splat', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'marker_default'},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '331', 'type': 'string', 'children': [], 'value': "'markers'"},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'category_name'},{'id': '338', 'type': 'for_in_clause', 'children': ['339', '342']},{'id': '339', 'type': 'tuple_pattern', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'category_name'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '344', 'type': 'argument_list', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'possible_categories'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'masks'},{'id': '347', 'type': 'pair', 'children': ['348', '349']},{'id': '348', 'type': 'string', 'children': [], 'value': "'layout'"},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'Layout'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'dictionary_splat', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'layout_default'},{'id': '354', 'type': 'return_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'offline_plotly_data'},{'id': '357', 'type': 'argument_list', 'children': ['358', '359', '362']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '362', 'type': 'keyword_argument', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'config_default'}
def offline_plotly_scatter_bubble(df, x='x', y='y', size_col='size', text_col='text', category_col='category', possible_categories=None, filename=None, config={'displaylogo': False}, xscale=None, yscale='log', layout={'hovermode': 'closest', 'showlegend': False, 'autosize': True}, marker={'sizemode': 'area'}, min_size=10, ): r config_default = dict(DEFAULT_PLOTLY_CONFIG) marker_default = { 'size': size_col or min_size, 'sizemode': 'area', 'sizeref': int(df[size_col].min() * .8) if size_col else min_size} marker_default.update(marker) size_col = marker_default.pop('size') layout_default = { 'xaxis': XAxis(title=x, type=xscale), 'yaxis': YAxis(title=y, type=yscale), } layout_default.update(**layout) if config is not None: config_default.update(config) df.columns = clean_columns(df.columns) if possible_categories is None and category_col is not None: if category_col in df.columns: category_labels = df[category_col] else: category_labels = np.array(category_col) possible_categories = list(set(category_labels)) possible_categories = [None] if possible_categories is None else possible_categories if category_col and category_col in df: masks = [np.array(df[category_col] == label) for label in possible_categories] else: masks = [np.array([True] * len(df))] * len(possible_categories) data = {'data': [ Scatter(x=df[x][mask].values, y=df[y][mask].values, text=df[text_col][mask].values, marker=Marker(size=df[size_col][mask] if size_col in df.columns else size_col, **marker_default), mode='markers', name=str(category_name)) for (category_name, mask) in zip(possible_categories, masks) ], 'layout': Layout(**layout_default) } return offline_plotly_data(data, filename=filename, config=config_default)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_acronyms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'manuscript'},{'id': '6', 'type': 'call', 'children': ['7', '12']},{'id': '7', 'type': 'attribute', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'~/code/nlpia/lane/manuscript'"},{'id': '14', 'type': 'block', 'children': ['15', '19', '156']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '23', '27']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get_lines'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'manuscript'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '31', 'type': 'block', 'children': ['32', '41']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'CRE_ACRONYM'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '41', 'type': 'if_statement', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '55', '75', '102', '129']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'a2'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'tuple', 'children': ['63', '69']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "'a2'"},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'s2'"},{'id': '75', 'type': 'elif_clause', 'children': ['76', '82']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'string', 'children': [], 'value': "'a3'"},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'tuple', 'children': ['90', '96']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': "'a3'"},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "'s3'"},{'id': '102', 'type': 'elif_clause', 'children': ['103', '109']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'a4'"},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'tuple', 'children': ['117', '123']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'a4'"},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'s4'"},{'id': '129', 'type': 'elif_clause', 'children': ['130', '136']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'a5'"},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'tuple', 'children': ['144', '150']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': "'a5'"},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'string', 'children': [], 'value': "'s5'"},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '167']},{'id': '161', 'type': 'attribute', 'children': ['162', '166']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'acronyms'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '167', 'type': 'argument_list', 'children': []}
def get_acronyms(manuscript=os.path.expanduser('~/code/nlpia/lane/manuscript')): acronyms = [] for f, lines in get_lines(manuscript): for line in lines: matches = CRE_ACRONYM.finditer(line) if matches: for m in matches: if m.group('a2'): acronyms.append((m.group('a2'), m.group('s2'))) elif m.group('a3'): acronyms.append((m.group('a3'), m.group('s3'))) elif m.group('a4'): acronyms.append((m.group('a4'), m.group('s4'))) elif m.group('a5'): acronyms.append((m.group('a5'), m.group('s5'))) return sorted(dict(acronyms).items())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_find'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rpcmethod'},{'id': '6', 'type': 'block', 'children': ['7', '23', '29', '51', '63', '67', '104', '112']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': '"crawling network with nearest: %s"'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '29', 'type': 'if_statement', 'children': ['30', '41']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '38'], 'value': '=='},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_ids'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'last_ids_crawled'},{'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': 'count'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'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': 'last_ids_crawled'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_ids'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '66', 'type': 'dictionary', 'children': []},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '80']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'peer'},{'id': '69', 'type': 'subscript', 'children': ['70', '77']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_uncontacted'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'slice', 'children': ['78', '79']},{'id': '78', 'type': 'colon', 'children': []},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '80', 'type': 'block', 'children': ['81', '95']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'peer'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'rpcmethod'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'peer'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'nearest'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'mark_contacted'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'peer'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '107', 'type': 'await', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'gather_dict'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'await', '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': '_nodes_found'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'found'}
async def _find(self, rpcmethod): log.info("crawling network with nearest: %s", str(tuple(self.nearest))) count = self.alpha if self.nearest.get_ids() == self.last_ids_crawled: count = len(self.nearest) self.last_ids_crawled = self.nearest.get_ids() dicts = {} for peer in self.nearest.get_uncontacted()[:count]: dicts[peer.id] = rpcmethod(peer, self.node) self.nearest.mark_contacted(peer) found = await gather_dict(dicts) return await self._nodes_found(found)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '8', 'type': 'type_parameter', 'children': ['9', '11', '13', '15']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'generic_type', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '18', 'type': 'type_parameter', 'children': ['19']},{'id': '19', 'type': 'type', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'WeightedPart'},{'id': '21', 'type': 'block', 'children': ['22', '34', '48']},{'id': '22', 'type': 'if_statement', 'children': ['23', '28']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': 'is'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '27', 'type': 'None', 'children': []},{'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': 'RuntimeError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': 'f"{self!r} is not bound to a Map"'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'complex_rule'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '39', 'type': 'generator_expression', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'converter'},{'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_weights'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'tuple', 'children': ['50', '57', '58', '65']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'complex_rule'},{'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_weights'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_weights'}
def match_key(self) -> Tuple[bool, bool, int, List[WeightedPart]]: if self.map is None: raise RuntimeError(f"{self!r} is not bound to a Map") complex_rule = any(weight.converter for weight in self._weights) return (not bool(self.defaults), complex_rule, -len(self._weights), self._weights)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'type', 'children': ['6']},{'id': '6', 'type': 'generic_type', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Tuple'},{'id': '8', 'type': 'type_parameter', 'children': ['9', '11']},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '13', 'type': 'block', 'children': ['14', '26']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': 'is'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': 'f"{self!r} is not bound to a Map"'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'tuple', 'children': ['28', '35']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '38', 'type': 'generator_expression', 'children': ['39', '40', '45']},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_weights'},{'id': '45', 'type': 'if_clause', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'converter'}
def build_key(self) -> Tuple[bool, int]: if self.map is None: raise RuntimeError(f"{self!r} is not bound to a Map") return (not bool(self.defaults), -sum(1 for weight in self._weights if weight.converter))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_ui_file'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'block', 'children': ['6', '14', '31']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ui'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'gtk'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ui'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'add_from_file'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'runtime'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data_dir'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ui'}
def load_ui_file(name): ui = gtk.Builder() ui.add_from_file(os.path.join(runtime.data_dir, name)) return ui
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__remove_category'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '6', 'type': 'block', 'children': ['7', '26', '30', '39', '48']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'affected_query'},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'affected_ids'},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '16']},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'res'},{'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': 'fetchall'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'affected_query'},{'id': '24', 'type': 'tuple', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '29', 'type': 'string', 'children': [], 'value': '"update activities set category_id = -1 where category_id = ?"'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '37', 'type': 'tuple', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': '"delete from categories where id = ?"'},{'id': '46', 'type': 'tuple', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__remove_index'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'affected_ids'}
def __remove_category(self, id): affected_query = affected_ids = [res[0] for res in self.fetchall(affected_query, (id,))] update = "update activities set category_id = -1 where category_id = ?" self.execute(update, (id, )) self.execute("delete from categories where id = ?", (id, )) self.__remove_index(affected_ids)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '13']},{'id': '8', 'type': 'subscript', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '12', 'type': 'string', 'children': [], 'value': "'_z_ordered_sprites'"},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sprites'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'lambda', 'children': ['22', '24']},{'id': '22', 'type': 'lambda_parameters', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sprite'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'z_order'}
def _sort(self): self.__dict__['_z_ordered_sprites'] = sorted(self.sprites, key=lambda sprite:sprite.z_order)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_mouse_cursor'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12', '17', '32']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'is'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'mouse_cursor'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'mouse_cursor'},{'id': '17', 'type': 'elif_clause', 'children': ['18', '25']},{'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'draggable'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'gdk'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'CursorType'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'FLEUR'},{'id': '32', 'type': 'elif_clause', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'gdk'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'CursorType'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'HAND2'}
def _get_mouse_cursor(self): if self.mouse_cursor is not None: return self.mouse_cursor elif self.interactive and self.draggable: return gdk.CursorType.FLEUR elif self.interactive: return gdk.CursorType.HAND2
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'entries'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '13', '31', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': 'u"Getting entries"'},{'id': '13', 'type': 'if_statement', 'children': ['14', '20']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'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': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'log_exc'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29', '30']},{'id': '27', 'type': 'string', 'children': [], 'value': 'u"This container does not exist. Wrong path?"'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '31', 'type': 'if_statement', 'children': ['32', '37']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': 'is'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'actual_container'},{'id': '36', 'type': 'None', 'children': []},{'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': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'log_exc'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46', '47']},{'id': '44', 'type': 'string', 'children': [], 'value': 'u"The actual container object has not been set"'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'True', 'children': []},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'actual_container'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'entries'}
def entries(self): self.log(u"Getting entries") if not self.exists(): self.log_exc(u"This container does not exist. Wrong path?", None, True, TypeError) if self.actual_container is None: self.log_exc(u"The actual container object has not been set", None, True, TypeError) return self.actual_container.entries
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19', '26', '37', '44', '51', '132', '139']},{'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': 'is_guaranteed_sorted'},{'id': '10', 'type': 'block', 'children': ['11', '18']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': 'u"Already sorted, returning"'},{'id': '18', 'type': 'return_statement', 'children': []},{'id': '19', 'type': 'expression_statement', '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': 'log'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': 'u"Sorting..."'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '__fragments'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '__fragments'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': 'u"Sorting... done"'},{'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': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': 'u"Checking relative positions..."'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '62']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '61'], 'value': '-'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'block', 'children': ['63', '71', '81']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'current_interval'},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'next_interval'},{'id': '74', 'type': 'attribute', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '81', 'type': 'if_statement', 'children': ['82', '92']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '89'], 'value': 'not'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'current_interval'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'relative_position_of'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'next_interval'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ALLOWED_POSITIONS'},{'id': '92', 'type': 'block', 'children': ['93', '100', '110', '122']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': 'u"Found overlapping fragments:"'},{'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': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'list', 'children': ['107', '108', '109'], 'value': '[u" Index %d => %s", i, current_interval]'},{'id': '107', 'type': 'string', 'children': [], 'value': 'u" Index %d => %s"'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'current_interval'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'list', 'children': ['117', '118', '121'], 'value': '[u" Index %d => %s", i + 1, next_interval]'},{'id': '117', 'type': 'string', 'children': [], 'value': 'u" Index %d => %s"'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'next_interval'},{'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': 'log_exc'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130', '131']},{'id': '128', 'type': 'string', 'children': [], 'value': 'u"The list contains two fragments overlapping in a forbidden way"'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': 'u"Checking relative positions... done"'},{'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': '__sorted'},{'id': '144', 'type': 'True', 'children': []}
def sort(self): if self.is_guaranteed_sorted: self.log(u"Already sorted, returning") return self.log(u"Sorting...") self.__fragments = sorted(self.__fragments) self.log(u"Sorting... done") self.log(u"Checking relative positions...") for i in range(len(self) - 1): current_interval = self[i].interval next_interval = self[i + 1].interval if current_interval.relative_position_of(next_interval) not in self.ALLOWED_POSITIONS: self.log(u"Found overlapping fragments:") self.log([u" Index %d => %s", i, current_interval]) self.log([u" Index %d => %s", i + 1, next_interval]) self.log_exc(u"The list contains two fragments overlapping in a forbidden way", None, True, ValueError) self.log(u"Checking relative positions... done") self.__sorted = True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '168', '182']},{'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': 'sorted'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': []},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'key'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '16', 'type': 'block', 'children': ['17', '21', '27', '85', '89', '120', '166']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'requested_key'},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'for_statement', 'children': ['28', '31', '39']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'solver'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'request_list'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '45']},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'conflict'},{'id': '45', 'type': 'block', 'children': ['46', '59']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'req'},{'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': 'variant'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'requires_list'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '76']},{'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': 'requested_key'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'tuple', 'children': ['71', '73']},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'range'},{'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': 'names'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '88', 'type': 'list', 'children': [], 'value': '[]'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '94']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'requires_list'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '106']},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '101'], 'value': 'and'},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'conflict'},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': 'not'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'tuple', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '120', 'type': 'if_statement', 'children': ['121', '131', '146']},{'id': '121', 'type': '()', 'children': ['122']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '128'], 'value': '=='},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'VariantSelectMode'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'variant_select_mode'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'VariantSelectMode'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'version_priority'},{'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': 'k'},{'id': '135', 'type': 'tuple', 'children': ['136', '137', '142', '143']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'requested_key'},{'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'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': 'k'},{'id': '151', 'type': 'tuple', 'children': ['152', '156', '157', '162', '163']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'requested_key'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'requested_key'},{'id': '157', 'type': 'unary_operator', 'children': ['158'], 'value': '-'},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'additional_key'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '166', 'type': 'return_statement', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'variants'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '175', 'type': 'argument_list', 'children': ['176', '179']},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '181', 'type': 'True', 'children': []},{'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': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '187', 'type': 'True', 'children': []}
def sort(self): if self.sorted: return def key(variant): requested_key = [] names = set() for i, request in enumerate(self.solver.request_list): if not request.conflict: req = variant.requires_list.get(request.name) if req is not None: requested_key.append((-i, req.range)) names.add(req.name) additional_key = [] for request in variant.requires_list: if not request.conflict and request.name not in names: additional_key.append((request.range, request.name)) if (VariantSelectMode[config.variant_select_mode] == VariantSelectMode.version_priority): k = (requested_key, -len(additional_key), additional_key, variant.index) else: k = (len(requested_key), requested_key, -len(additional_key), additional_key, variant.index) return k self.variants.sort(key=key, reverse=True) self.sorted = True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_versions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '79', '101', '107']},{'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': 'sorted'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '22']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'orderer'},{'id': '14', 'type': '()', 'children': ['15']},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'or'},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'solver'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'package_orderers'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'block', 'children': ['23', '42']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'orderer'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'reorder'},{'id': '30', 'type': 'argument_list', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'lambda', 'children': ['37', '39']},{'id': '37', 'type': 'lambda_parameters', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '53', '59', '78']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '74']},{'id': '70', 'type': 'string', 'children': [], 'value': '"sorted: %s packages: %s"'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'package_name'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'orderer'},{'id': '78', 'type': 'return_statement', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90', '98']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'lambda', 'children': ['93', '95']},{'id': '93', 'type': 'lambda_parameters', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '100', 'type': 'True', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '106', 'type': 'True', 'children': []},{'id': '107', 'type': 'if_statement', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'pr'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': '"sorted: %s packages: version descending"'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'package_name'}
def sort_versions(self): if self.sorted: return for orderer in (self.solver.package_orderers or []): entries = orderer.reorder(self.entries, key=lambda x: x.package) if entries is not None: self.entries = entries self.sorted = True if self.pr: self.pr("sorted: %s packages: %s", self.package_name, repr(orderer)) return self.entries = sorted(self.entries, key=lambda x: x.version, reverse=True) self.sorted = True if self.pr: self.pr("sorted: %s packages: version descending", self.package_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_reset'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '6', 'type': 'block', 'children': ['7', '18', '24', '30', '38', '46']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14', '17']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'iadd'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_lists'},{'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': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_clear'},{'id': '23', 'type': 'argument_list', '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': '_load'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'load'},{'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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_half'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '>>'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_dual'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '<<'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '45', 'type': 'integer', 'children': [], 'value': '1'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'values'}
def _reset(self, load): values = reduce(iadd, self._lists, []) self._clear() self._load = load self._half = load >> 1 self._dual = load << 1 self._update(values)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19', '43', '50', '57', '72', '90', '116', '137', '153', '159', '209', '221']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_lists'},{'id': '19', 'type': 'if_statement', 'children': ['20', '26']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '=='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'block', 'children': ['27', '36', '42']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '35']},{'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': '_index'},{'id': '33', 'type': 'slice', 'children': ['34']},{'id': '34', 'type': 'colon', 'children': []},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_offset'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'return_statement', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'starmap'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '72', 'type': 'if_statement', 'children': ['73', '79']},{'id': '73', 'type': 'binary_operator', 'children': ['74', '78'], 'value': '&'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'if_statement', 'children': ['91', '97']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '96'], 'value': '=='},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'block', 'children': ['98', '109', '115']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '106']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_index'},{'id': '104', 'type': 'slice', 'children': ['105']},{'id': '105', 'type': 'colon', 'children': []},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_offset'},{'id': '114', 'type': 'integer', 'children': [], 'value': '1'},{'id': '115', 'type': 'return_statement', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '**'},{'id': '120', 'type': 'integer', 'children': [], 'value': '2'},{'id': '121', 'type': '()', 'children': ['122']},{'id': '122', 'type': 'binary_operator', 'children': ['123', '136'], 'value': '+'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'log_e'},{'id': '128', 'type': 'argument_list', 'children': ['129', '135']},{'id': '129', 'type': 'binary_operator', 'children': ['130', '134'], 'value': '-'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'integer', 'children': [], 'value': '2'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '156', 'type': 'list', 'children': ['157', '158'], 'value': '[row0, row1]'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'row0'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'row1'},{'id': '159', 'type': 'while_statement', 'children': ['160', '169']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '168'], 'value': '>'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '166', 'type': 'unary_operator', 'children': ['167'], 'value': '-'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'block', 'children': ['170', '180', '187', '202']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '178', 'type': 'unary_operator', 'children': ['179'], 'value': '-'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'starmap'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214', '218']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'iadd'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_index'},{'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': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': '_offset'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '-'},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '*'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '229', 'type': 'integer', 'children': [], 'value': '2'},{'id': '230', 'type': 'integer', 'children': [], 'value': '1'}
def _build_index(self): row0 = list(map(len, self._lists)) if len(row0) == 1: self._index[:] = row0 self._offset = 0 return head = iter(row0) tail = iter(head) row1 = list(starmap(add, zip(head, tail))) if len(row0) & 1: row1.append(row0[-1]) if len(row1) == 1: self._index[:] = row1 + row0 self._offset = 1 return size = 2 ** (int(log_e(len(row1) - 1, 2)) + 1) row1.extend(repeat(0, size - len(row1))) tree = [row0, row1] while len(tree[-1]) > 1: head = iter(tree[-1]) tail = iter(head) row = list(starmap(add, zip(head, tail))) tree.append(row) reduce(iadd, reversed(tree), self._index) self._offset = size * 2 - 1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_fromset'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '19', '25', '34']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted_set'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__new__'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted_set'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_set'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted_set'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '__init__'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted_set'}
def _fromset(cls, values, key=None): sorted_set = object.__new__(cls) sorted_set._set = values sorted_set.__init__(key=key) return sorted_set
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_argsort_and_resolve_ties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '6', 'type': 'block', 'children': ['7', '14', '26', '30', '87']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_samples'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '25', 'type': 'string', 'children': [], 'value': '"mergesort"'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'while_statement', 'children': ['31', '36']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '<'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '-'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'n_samples'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'block', 'children': ['37', '43', '64', '83']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'while_statement', 'children': ['44', '59']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '48'], 'value': 'and'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'n_samples'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '54'], 'value': '=='},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'if_statement', 'children': ['65', '70']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '!='},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '79', 'type': 'slice', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '81', 'type': 'colon', 'children': []},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'inext'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'order'}
def _argsort_and_resolve_ties(time, random_state): n_samples = len(time) order = numpy.argsort(time, kind="mergesort") i = 0 while i < n_samples - 1: inext = i + 1 while inext < n_samples and time[order[i]] == time[order[inext]]: inext += 1 if i + 1 != inext: random_state.shuffle(order[i:inext]) i = inext return order
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'toposort_classes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '5', 'type': 'block', 'children': ['6', '131', '143', '149', '153', '176']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '13']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'get_class_topolist'},{'id': '8', 'type': 'parameters', 'children': ['9', '10', '11', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'name_to_class'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'processed_classes'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'current_trace'},{'id': '13', 'type': 'block', 'children': ['14', '21', '36', '42', '49', '60', '78', '82', '89', '106', '113', '122', '129']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'processed_classes'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'list', 'children': [], 'value': '[]'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'current_trace'},{'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': 'AssertionError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Encountered self-reference in dependency chain of {}'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name_to_class'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_list_superclasses'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '52', 'type': 'conditional_expression', 'children': ['53', '56', '59'], 'value': 'if'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '55', 'type': 'string', 'children': [], 'value': "'properties'"},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'string', 'children': [], 'value': "'properties'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '59', 'type': 'list', 'children': [], 'value': '[]'},{'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': "'linkedClass'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '77', 'type': 'string', 'children': [], 'value': "'linkedClass'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'class_list'},{'id': '81', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'current_trace'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'class_list'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_class_topolist'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104', '105']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dependency'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'name_to_class'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'processed_classes'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'current_trace'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'current_trace'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'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': 'class_list'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name_to_class'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'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': 'processed_classes'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'class_list'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'class_map'},{'id': '134', 'type': 'dictionary_comprehension', 'children': ['135', '140']},{'id': '135', 'type': 'pair', 'children': ['136', '139']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '138', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'seen_classes'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'toposorted'},{'id': '152', 'type': 'list', 'children': [], 'value': '[]'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '160']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'class_map'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'toposorted'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'get_class_topolist'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '173']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'class_map'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'seen_classes'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'toposorted'}
def toposort_classes(classes): def get_class_topolist(class_name, name_to_class, processed_classes, current_trace): if class_name in processed_classes: return [] if class_name in current_trace: raise AssertionError( 'Encountered self-reference in dependency chain of {}'.format(class_name)) cls = name_to_class[class_name] dependencies = _list_superclasses(cls) properties = cls['properties'] if 'properties' in cls else [] for prop in properties: if 'linkedClass' in prop: dependencies.append(prop['linkedClass']) class_list = [] current_trace.add(class_name) for dependency in dependencies: class_list.extend(get_class_topolist( dependency, name_to_class, processed_classes, current_trace)) current_trace.remove(class_name) class_list.append(name_to_class[class_name]) processed_classes.add(class_name) return class_list class_map = {c['name']: c for c in classes} seen_classes = set() toposorted = [] for name in class_map.keys(): toposorted.extend(get_class_topolist(name, class_map, seen_classes, set())) return toposorted
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_steps'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '20', '27', '31', '58']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_check_old_yaml_format'},{'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': 'config_steps'},{'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': 'flow_config'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_check_infinite_flows'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config_steps'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'for_statement', 'children': ['32', '35', '40']},{'id': '32', 'type': 'pattern_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'step_config'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'config_steps'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '51']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'specs'},{'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': '_visit_step'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'step_config'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'specs'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"step_num"'}
def _init_steps(self,): self._check_old_yaml_format() config_steps = self.flow_config.steps self._check_infinite_flows(config_steps) steps = [] for number, step_config in config_steps.items(): specs = self._visit_step(number, step_config) steps.extend(specs) return sorted(steps, key=attrgetter("step_num"))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ranker'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '7', 'type': 'block', 'children': ['8', '23', '37', '45', '55', '65', '71']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'total_score'},{'id': '11', 'type': 'call', 'children': ['12', '22']},{'id': '12', 'type': 'attribute', 'children': ['13', '21']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'transpose'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'total_score'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'squeeze'},{'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': 'asarray'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'total_score'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'total_score'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '50', 'type': 'slice', 'children': ['51', '52', '53']},{'id': '51', 'type': 'colon', 'children': []},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'unary_operator', 'children': ['54'], 'value': '-'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_meta'},{'id': '58', 'type': 'list_comprehension', 'children': ['59', '62']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted_X'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'tuple', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted_X'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sorted_meta'}
def ranker(self, X, meta): total_score = X.sum(axis=1).transpose() total_score = np.squeeze(np.asarray(total_score)) ranks = total_score.argsort() ranks = ranks[::-1] sorted_meta = [meta[r] for r in ranks] sorted_X = X[ranks] return (sorted_X, sorted_meta)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_pickled_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'idevice'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '6', 'type': 'block', 'children': ['7', '11', '27', '31', '39', '52']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'idevice'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'subscript', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'idevice'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pickle_file'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'location'},{'id': '38', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'pickle'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'pickle_file'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'protocol'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pickle'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'HIGHEST_PROTOCOL'},{'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': 'pickle_file'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '57', 'type': 'argument_list', 'children': []}
def create_pickled_data(idevice, filename): data = {} for x in idevice.content: data[x] = idevice.content[x] location = filename pickle_file = open(location, 'wb') pickle.dump(data, pickle_file, protocol=pickle.HIGHEST_PROTOCOL) pickle_file.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_html_string'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '17', '42']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_get_options'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '17', 'type': 'if_statement', 'children': ['18', '21', '31']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '20', 'type': 'string', 'children': [], 'value': '"format"'},{'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': 'string'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_get_formatted_html_string'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'string'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_get_simple_html_string'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'string'}
def get_html_string(self, **kwargs): options = self._get_options(kwargs) if options["format"]: string = self._get_formatted_html_string(options) else: string = self._get_simple_html_string(options) return string
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_last_update_time'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '28']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Gets the time at which each ledger was updated.\n Can be called at any time to get this information.\n :return: an ordered dict of outdated ledgers sorted by last update time (from old to new)\n and then by ledger ID (in case of equal update time)\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'last_updated'},{'id': '11', 'type': 'dictionary_comprehension', 'children': ['12', '17']},{'id': '12', 'type': 'pair', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'ledger_id'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'freshness_state'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'last_updated'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ledger_id'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'freshness_state'},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_ledger_freshness'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '34', 'type': 'argument_list', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'last_updated'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'lambda', 'children': ['43', '45']},{'id': '43', 'type': 'lambda_parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '45', 'type': 'tuple', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'}
def get_last_update_time(self): ''' Gets the time at which each ledger was updated. Can be called at any time to get this information. :return: an ordered dict of outdated ledgers sorted by last update time (from old to new) and then by ledger ID (in case of equal update time) ''' last_updated = {ledger_id: freshness_state.last_updated for ledger_id, freshness_state in self._ledger_freshness.items()} return OrderedDict( sorted( last_updated.items(), key=lambda item: (item[1], item[0]) ) )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_listChunks'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '42']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '20']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fileName'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dataDir'},{'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': 'index'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ChunkedFileStore'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_fileNameToChunkIndex'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'fileName'},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35']},{'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': 'chunks'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'chunks'}
def _listChunks(self): chunks = [] for fileName in os.listdir(self.dataDir): index = ChunkedFileStore._fileNameToChunkIndex(fileName) if index is not None: chunks.append(index) return sorted(chunks)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mostCommonElement'},{'id': '3', 'type': 'parameters', 'children': ['4', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '16']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'to_hashable_f'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Callable'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '110', '121', '139']},{'id': '18', 'type': 'class_definition', 'children': ['19', '20', '26']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_Hashable'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'abc'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Hashable'},{'id': '26', 'type': 'block', 'children': ['27', '84', '98']},{'id': '27', 'type': 'function_definition', 'children': ['28', '29', '32']},{'id': '28', 'type': 'function_name', 'children': [], 'value': '__init__'},{'id': '29', 'type': 'parameters', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '32', 'type': 'block', 'children': ['33', '39']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '39', 'type': 'if_statement', 'children': ['40', '47', '54', '68']},{'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': 'orig'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'Hashable'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '54', 'type': 'elif_clause', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'to_hashable_f'},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'to_hashable_f'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '68', 'type': 'else_clause', 'children': ['69']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '83', 'type': 'True', 'children': []},{'id': '84', 'type': 'function_definition', 'children': ['85', '86', '89']},{'id': '85', 'type': 'function_name', 'children': [], 'value': '__eq__'},{'id': '86', 'type': 'parameters', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '=='},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '102']},{'id': '99', 'type': 'function_name', 'children': [], 'value': '__hash__'},{'id': '100', 'type': 'parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'hashable'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '113', 'type': 'generator_expression', 'children': ['114', '118']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_Hashable'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '126', 'type': 'subscript', 'children': ['127', '138']},{'id': '127', 'type': 'call', 'children': ['128', '134']},{'id': '128', 'type': 'attribute', 'children': ['129', '133']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_elements'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'expression_list', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'orig'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'counter'}
def mostCommonElement(elements: Iterable[T], to_hashable_f: Callable=None): class _Hashable(collections.abc.Hashable): def __init__(self, orig): self.orig = orig if isinstance(orig, collections.Hashable): self.hashable = orig elif to_hashable_f is not None: self.hashable = to_hashable_f(orig) else: self.hashable = json.dumps(orig, sort_keys=True) def __eq__(self, other): return self.hashable == other.hashable def __hash__(self): return hash(self.hashable) _elements = (_Hashable(el) for el in elements) most_common, counter = Counter(_elements).most_common(n=1)[0] return most_common.orig, counter
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'minute_index_to_session_labels'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'block', 'children': ['7', '18', '39', '58', '65', '156']},{'id': '7', 'type': 'if_statement', 'children': ['8', '12']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_monotonic_increasing'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'raise_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Non-ordered index passed to minute_index_to_session_labels."'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'prev_opens'},{'id': '21', 'type': '()', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '38'], 'value': '-'},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_opens'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '37', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'next_closes'},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '51']},{'id': '44', 'type': 'attribute', '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': '_closes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '57', 'type': 'string', 'children': [], 'value': "'left'"},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'mismatches'},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '!='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'prev_opens'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'next_closes'},{'id': '65', 'type': 'if_statement', 'children': ['66', '71']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'mismatches'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'block', 'children': ['72', '83', '89', '95', '107', '121']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'bad_ix'},{'id': '75', 'type': 'subscript', 'children': ['76', '82']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'mismatches'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'example'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'bad_ix'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'prev_day'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'prev_opens'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'bad_ix'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'pattern_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'prev_open'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'prev_close'},{'id': '100', 'type': 'subscript', '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': 'schedule'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'prev_day'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'pattern_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'next_open'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'next_close'},{'id': '112', 'type': 'subscript', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'iloc'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'prev_day'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '133']},{'id': '126', 'type': 'attribute', 'children': ['127', '132']},{'id': '127', 'type': 'concatenated_string', 'children': ['128', '129', '130', '131']},{'id': '128', 'type': 'string', 'children': [], 'value': '"{num} non-market minutes in minute_index_to_session_labels:\\n"'},{'id': '129', 'type': 'string', 'children': [], 'value': '"First Bad Minute: {first_bad}\\n"'},{'id': '130', 'type': 'string', 'children': [], 'value': '"Previous Session: {prev_open} -> {prev_close}\\n"'},{'id': '131', 'type': 'string', 'children': [], 'value': '"Next Session: {next_open} -> {next_close}"'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '133', 'type': 'argument_list', 'children': ['134', '141', '144', '147', '150', '153']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'mismatches'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'first_bad'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'example'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'prev_open'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'prev_open'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'prev_close'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'prev_close'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'next_open'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'next_open'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'next_close'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'next_close'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'subscript', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'schedule'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'prev_opens'}
def minute_index_to_session_labels(self, index): if not index.is_monotonic_increasing: raise ValueError( "Non-ordered index passed to minute_index_to_session_labels." ) prev_opens = ( self._opens.values.searchsorted(index.values, side='right') - 1 ) next_closes = ( self._closes.values.searchsorted(index.values, side='left') ) mismatches = (prev_opens != next_closes) if mismatches.any(): bad_ix = np.flatnonzero(mismatches)[0] example = index[bad_ix] prev_day = prev_opens[bad_ix] prev_open, prev_close = self.schedule.iloc[prev_day] next_open, next_close = self.schedule.iloc[prev_day + 1] raise ValueError( "{num} non-market minutes in minute_index_to_session_labels:\n" "First Bad Minute: {first_bad}\n" "Previous Session: {prev_open} -> {prev_close}\n" "Next Session: {next_open} -> {next_close}" .format( num=mismatches.sum(), first_bad=example, prev_open=prev_open, prev_close=prev_close, next_open=next_open, next_close=next_close) ) return self.schedule.index[prev_opens]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'aggregate_repeated_calls'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '6', 'type': 'block', 'children': ['7', '9', '16', '20', '79', '93', '110']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Converts a timeline into a time-aggregate summary.\n Adds together calls along the same call stack, so that repeated calls appear as the same\n frame. Removes time-linearity - frames are sorted according to total time spent.\n Useful for outputs that display a summary of execution (e.g. text and html outputs)\n '''"},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'children_by_identifier'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '25']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32', '69']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'in'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'children_by_identifier'},{'id': '32', 'type': 'block', 'children': ['33', '41', '49', '63']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'aggregate_frame'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'children_by_identifier'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '46'], 'value': '+='},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'aggregate_frame'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self_time'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self_time'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'children'},{'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': 'aggregate_frame'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_children'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'remove_from_parent'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '78']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'children_by_identifier'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'identifier'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '84']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'aggregate_repeated_calls'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_children'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '100', 'type': 'argument_list', 'children': ['101', '107']},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'methodcaller'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '109', 'type': 'True', 'children': []},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'frame'}
def aggregate_repeated_calls(frame, options): ''' Converts a timeline into a time-aggregate summary. Adds together calls along the same call stack, so that repeated calls appear as the same frame. Removes time-linearity - frames are sorted according to total time spent. Useful for outputs that display a summary of execution (e.g. text and html outputs) ''' if frame is None: return None children_by_identifier = {} for child in frame.children: if child.identifier in children_by_identifier: aggregate_frame = children_by_identifier[child.identifier] aggregate_frame.self_time += child.self_time if child.children: aggregate_frame.add_children(child.children) child.remove_from_parent() else: children_by_identifier[child.identifier] = child for child in frame.children: aggregate_repeated_calls(child, options=options) frame._children.sort(key=methodcaller('time'), reverse=True) return frame
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_all_tags_names_as_list'},{'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': 'admin'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '10', 'type': 'string', 'children': [], 'value': '"en"'},{'id': '11', 'type': 'block', 'children': ['12', '55', '61', '67', '78', '126', '147', '168', '177']},{'id': '12', 'type': 'if_statement', 'children': ['13', '14', '34']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '27']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '22'], 'value': 'and'},{'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': '_all_tags_cache_list_admin'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list_admin'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'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': '_all_tags_cache_list_admin'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '48']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '43'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '!='},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list'},{'id': '42', 'type': 'dictionary', 'children': []},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 's_stud'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 's_admin'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '73']},{'id': '69', 'type': 'tuple_pattern', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'org'},{'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': 'get_all_tags'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '83']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '83', 'type': 'block', 'children': ['84', '105', '112']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tag_name_with_translation'},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '99', '104'], 'value': 'if'},{'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': 'gettext'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '103', 'type': 'argument_list', 'children': []},{'id': '104', 'type': 'string', 'children': [], 'value': '""'},{'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': 's_admin'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tag_name_with_translation'},{'id': '112', 'type': 'if_statement', 'children': ['113', '118']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'is_visible_for_student'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 's_stud'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tag_name_with_translation'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '133']},{'id': '128', 'type': 'subscript', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list_admin'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 's_admin'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'lambda', 'children': ['140', '142']},{'id': '140', 'type': 'lambda_parameters', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '154']},{'id': '149', 'type': 'subscript', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 's_stud'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '160', 'type': 'lambda', 'children': ['161', '163']},{'id': '161', 'type': 'lambda_parameters', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'admin'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list_admin'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'subscript', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '_all_tags_cache_list'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'language'}
def get_all_tags_names_as_list(self, admin=False, language="en"): if admin: if self._all_tags_cache_list_admin != {} and language in self._all_tags_cache_list_admin: return self._all_tags_cache_list_admin[language] else: if self._all_tags_cache_list != {} and language in self._all_tags_cache_list: return self._all_tags_cache_list[language] s_stud = set() s_admin = set() (common, _, org) = self.get_all_tags() for tag in common + org: tag_name_with_translation = self.gettext(language, tag.get_name()) if tag.get_name() else "" s_admin.add(tag_name_with_translation) if tag.is_visible_for_student(): s_stud.add(tag_name_with_translation) self._all_tags_cache_list_admin[language] = natsorted(s_admin, key=lambda y: y.lower()) self._all_tags_cache_list[language] = natsorted(s_stud, key=lambda y: y.lower()) if admin: return self._all_tags_cache_list_admin[language] return self._all_tags_cache_list[language]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_users'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'course'},{'id': '6', 'type': 'block', 'children': ['7', '55']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16', '38']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '37']},{'id': '20', 'type': 'attribute', 'children': ['21', '36']},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'user_manager'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_users_info'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'user_manager'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_course_registered_users'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'course'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'lambda', 'children': ['41', '43']},{'id': '41', 'type': 'lambda_parameters', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '43', 'type': 'conditional_expression', 'children': ['44', '49', '54'], 'value': 'if'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '53'], 'value': 'is'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'string', 'children': [], 'value': '""'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'users'}
def get_users(self, course): users = OrderedDict(sorted(list(self.user_manager.get_users_info(self.user_manager.get_course_registered_users(course)).items()), key=lambda k: k[1][0] if k[1] is not None else "")) return users
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'radius_cmp'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '7', 'type': 'block', 'children': ['8', '10', '24', '31', '39']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''return +1 or -1 for for sorting'''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '19'], 'value': '-'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'radius'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'offsets'},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '>'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '<'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'}
def radius_cmp(a, b, offsets): '''return +1 or -1 for for sorting''' diff = radius(a, offsets) - radius(b, offsets) if diff > 0: return 1 if diff < 0: return -1 return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_enums_info'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'enums'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'msgs'},{'id': '6', 'type': 'block', 'children': ['7', '230']},{'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'enums'},{'id': '10', 'type': 'block', 'children': ['11', '22', '32', '38', '70', '74', '78', '194', '205', '216']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'swift_name'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'camel_case_from_underscores'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'enum'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'raw_value_type'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_enum_raw_type'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'msgs'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'formatted_description'},{'id': '37', 'type': 'string', 'children': [], 'value': '""'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '42', 'type': 'block', 'children': ['43', '60']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': '" "'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'formatted_description'},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'},{'id': '66', 'type': 'string', 'children': [], 'value': '"\\n/**\\n %s\\n*/\\n"'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'all_entities'},{'id': '73', 'type': 'list', 'children': [], 'value': '[]'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'entities_info'},{'id': '77', 'type': 'list', 'children': [], 'value': '[]'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '83']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '83', 'type': 'block', 'children': ['84', '100', '115', '124', '130', '164', '173']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '93', 'type': 'argument_list', 'children': ['94', '99']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '98'], 'value': '+'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '98', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '99', 'type': 'string', 'children': [], 'value': "''"},{'id': '100', 'type': 'if_statement', 'children': ['101', '108']},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '107', 'type': 'argument_list', 'children': []},{'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': 'name'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '+'},{'id': '113', 'type': 'string', 'children': [], 'value': '"MAV_"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'entry'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'swift_name'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'camel_case_from_underscores'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'entry'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'formatted_description'},{'id': '129', 'type': 'string', 'children': [], 'value': '""'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '134', 'type': 'block', 'children': ['135', '152']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '" "'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'formatted_description'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '163'], 'value': '+'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '+'},{'id': '159', 'type': 'string', 'children': [], 'value': '"\\n\\t/// "'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '163', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'all_entities'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'swift_name'},{'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': 'entities_info'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '%'},{'id': '180', 'type': 'string', 'children': [], 'value': '\'("%s", "%s")\''},{'id': '181', 'type': 'tuple', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '193', 'type': 'string', 'children': [], 'value': '\'\\\\"\''},{'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': 'enum'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'all_entities'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': '", "'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'all_entities'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'entities_info'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '", "'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'entities_info'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'entity_description'},{'id': '221', 'type': 'call', 'children': ['222', '227']},{'id': '222', 'type': 'attribute', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '229', 'type': 'string', 'children': [], 'value': '\'\\\\"\''},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'enums'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '238', 'type': 'lambda', 'children': ['239', '241']},{'id': '239', 'type': 'lambda_parameters', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'enum'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'swift_name'}
def generate_enums_info(enums, msgs): for enum in enums: enum.swift_name = camel_case_from_underscores(enum.name) enum.raw_value_type = get_enum_raw_type(enum, msgs) enum.formatted_description = "" if enum.description: enum.description = " ".join(enum.description.split()) enum.formatted_description = "\n/**\n %s\n*/\n" % enum.description all_entities = [] entities_info = [] for entry in enum.entry: name = entry.name.replace(enum.name + '_', '') if name[0].isdigit(): name = "MAV_" + name entry.swift_name = camel_case_from_underscores(name) entry.formatted_description = "" if entry.description: entry.description = " ".join(entry.description.split()) entry.formatted_description = "\n\t/// " + entry.description + "\n" all_entities.append(entry.swift_name) entities_info.append('("%s", "%s")' % (entry.name, entry.description.replace('"','\\"'))) enum.all_entities = ", ".join(all_entities) enum.entities_info = ", ".join(entities_info) enum.entity_description = enum.description.replace('"','\\"') enums.sort(key = lambda enum : enum.swift_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_report_print'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'best_name'},{'id': '7', 'type': 'block', 'children': ['8', '16', '42', '98', '102', '113', '140', '144', '219', '230']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'title_items'},{'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15'], 'value': '["Rank", "Name", "Class-Score", "Overall-Score"]'},{'id': '12', 'type': 'string', 'children': [], 'value': '"Rank"'},{'id': '13', 'type': 'string', 'children': [], 'value': '"Name"'},{'id': '14', 'type': 'string', 'children': [], 'value': '"Class-Score"'},{'id': '15', 'type': 'string', 'children': [], 'value': '"Overall-Score"'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'class_scores_len'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '21', 'type': 'argument_list', 'children': ['22', '34']},{'id': '22', 'type': 'lambda', 'children': ['23', '25']},{'id': '23', 'type': 'lambda_parameters', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '33', 'type': 'string', 'children': [], 'value': '"class"'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'shifts'},{'id': '45', 'type': 'list', 'children': ['46', '59', '85'], 'value': '["%-" +\n str(len(sorted_list) +\n 4) +\n "s", "%-" +\n str(max(map(lambda x: len(str(x)), sorted_list)) +\n 4) +\n "s", "%-" +\n str(max(class_scores_len) + 11) + "s"]'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '58'], 'value': '+'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'string', 'children': [], 'value': '"%-"'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'binary_operator', 'children': ['53', '57'], 'value': '+'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '57', 'type': 'integer', 'children': [], 'value': '4'},{'id': '58', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '84'], 'value': '+'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'},{'id': '61', 'type': 'string', 'children': [], 'value': '"%-"'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '83'], 'value': '+'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '71', 'type': 'argument_list', 'children': ['72', '82']},{'id': '72', 'type': 'lambda', 'children': ['73', '75']},{'id': '73', 'type': 'lambda_parameters', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '83', 'type': 'integer', 'children': [], 'value': '4'},{'id': '84', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '97'], 'value': '+'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '+'},{'id': '87', 'type': 'string', 'children': [], 'value': '"%-"'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '96'], 'value': '+'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'class_scores_len'},{'id': '96', 'type': 'integer', 'children': [], 'value': '11'},{'id': '97', 'type': 'string', 'children': [], 'value': '"s"'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '101', 'type': 'string', 'children': [], 'value': '""'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '112'], 'value': '+'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'string', 'children': [], 'value': '"Best : "'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'best_name'},{'id': '112', 'type': 'string', 'children': [], 'value': '"\\n\\n"'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '139'], 'value': '+'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '135'], 'value': '+'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '126'], 'value': '%'},{'id': '119', 'type': '()', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': '""'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'shifts'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'title_items'},{'id': '131', 'type': 'slice', 'children': ['132', '133']},{'id': '132', 'type': 'colon', 'children': []},{'id': '133', 'type': 'unary_operator', 'children': ['134'], 'value': '-'},{'id': '134', 'type': 'integer', 'children': [], 'value': '1'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'title_items'},{'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'prev_rank'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'for_statement', 'children': ['145', '148', '152']},{'id': '145', 'type': 'pattern_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '152', 'type': 'block', 'children': ['153', '157', '174', '215']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '157', 'type': 'if_statement', 'children': ['158', '169']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '=='},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'prev_rank'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'prev_rank'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '214'], 'value': '+'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '206'], 'value': '+'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '187'], 'value': '%'},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': '""'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'shifts'},{'id': '187', 'type': 'tuple', 'children': ['188', '194', '198']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '+'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '205', 'type': 'string', 'children': [], 'value': '"class"'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'subscript', 'children': ['210', '213']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'cm'},{'id': '213', 'type': 'string', 'children': [], 'value': '"overall"'},{'id': '214', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'prev_rank'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '219', 'type': 'if_statement', 'children': ['220', '223']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'is'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'best_name'},{'id': '222', 'type': 'None', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'augmented_assignment', 'children': ['226', '227'], 'value': '+='},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'},{'id': '228', 'type': 'string', 'children': [], 'value': '"\\nWarning: "'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'COMPARE_RESULT_WARNING'},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'result'}
def compare_report_print(sorted_list, scores, best_name): title_items = ["Rank", "Name", "Class-Score", "Overall-Score"] class_scores_len = map(lambda x: len( str(x["class"])), list(scores.values())) shifts = ["%-" + str(len(sorted_list) + 4) + "s", "%-" + str(max(map(lambda x: len(str(x)), sorted_list)) + 4) + "s", "%-" + str(max(class_scores_len) + 11) + "s"] result = "" result += "Best : " + str(best_name) + "\n\n" result += ("".join(shifts) ) % tuple(title_items[:-1]) + title_items[-1] + "\n" prev_rank = 0 for index, cm in enumerate(sorted_list): rank = index if scores[sorted_list[rank]] == scores[sorted_list[prev_rank]]: rank = prev_rank result += ("".join(shifts)) % (str(rank + 1), str(cm), str(scores[cm]["class"])) + str(scores[cm]["overall"]) + "\n" prev_rank = rank if best_name is None: result += "\nWarning: " + COMPARE_RESULT_WARNING return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace_cells'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sorted_row_idxs'},{'id': '7', 'type': 'block', 'children': ['8', '15', '19', '23', '35', '106', '121']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '14']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'new_keys'},{'id': '18', 'type': 'dictionary', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'del_keys'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_selection'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'for_statement', 'children': ['36', '40', '45']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '__col'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '__tab'},{'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': 'grid'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'code_array'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'if_statement', 'children': ['47', '61']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '51', '52'], 'value': 'and'},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='},{'id': '49', 'type': 'identifier', 'children': [], 'value': '__tab'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tab'},{'id': '51', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '52', 'type': '()', 'children': ['53']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '56'], 'value': 'or'},{'id': '54', 'type': 'not_operator', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '60'], 'value': 'in'},{'id': '57', 'type': 'tuple', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '__col'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'selection'},{'id': '61', 'type': 'block', 'children': ['62', '71']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'new_row'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted_row_idxs'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '71', 'type': 'if_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '!='},{'id': '73', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'new_row'},{'id': '75', 'type': 'block', 'children': ['76', '96']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '84', '85']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'new_keys'},{'id': '80', 'type': 'tuple', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'new_row'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '__col'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '__tab'},{'id': '84', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'code_array'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'tuple', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '__col'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__tab'},{'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': 'del_keys'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'tuple', 'children': ['103', '104', '105']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '__row'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '__col'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '__tab'},{'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'del_keys'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '119']},{'id': '112', 'type': 'attribute', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'code_array'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'new_keys'},{'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': 'CellActions'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'set_code'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'new_keys'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'}
def replace_cells(self, key, sorted_row_idxs): row, col, tab = key new_keys = {} del_keys = [] selection = self.grid.actions.get_selection() for __row, __col, __tab in self.grid.code_array: if __tab == tab and \ (not selection or (__row, __col) in selection): new_row = sorted_row_idxs.index(__row) if __row != new_row: new_keys[(new_row, __col, __tab)] = \ self.grid.code_array((__row, __col, __tab)) del_keys.append((__row, __col, __tab)) for key in del_keys: self.grid.code_array.pop(key) for key in new_keys: CellActions.set_code(self, key, new_keys[key])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'OnSortAscending'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'block', 'children': ['7', '62']},{'id': '7', 'type': 'try_statement', 'children': ['8', '46']},{'id': '8', 'type': 'block', 'children': ['9', '39']},{'id': '9', 'type': 'with_statement', 'children': ['10', '21']},{'id': '10', 'type': 'with_clause', 'children': ['11']},{'id': '11', 'type': 'with_item', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'undo'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"Sort ascending"'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_ascending'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'actions'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'statustext'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': 'u"Sorting complete."'},{'id': '46', 'type': 'except_clause', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'statustext'},{'id': '53', 'type': 'call', 'children': ['54', '60']},{'id': '54', 'type': 'attribute', 'children': ['55', '59']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': 'u"Sorting failed: {}"'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'post_command_event'},{'id': '65', 'type': 'argument_list', 'children': ['66', '71', '76']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'main_window'},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'StatusBarMsg'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'statustext'}
def OnSortAscending(self, event): try: with undo.group(_("Sort ascending")): self.grid.actions.sort_ascending(self.grid.actions.cursor) statustext = _(u"Sorting complete.") except Exception, err: statustext = _(u"Sorting failed: {}").format(err) post_command_event(self.grid.main_window, self.grid.StatusBarMsg, text=statustext)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_font_list'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '13', '29', '35']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'font_map'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'pangocairo'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'cairo_font_map_get_default'},{'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': 'font_list'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'font_map'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'list_families'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'font_list'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'font_list'}
def get_font_list(): font_map = pangocairo.cairo_font_map_get_default() font_list = [f.get_name() for f in font_map.list_families()] font_list.sort() return font_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_keys'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'startkey'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '24', '71', '84', '98', '112']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tuple_key'},{'id': '14', 'type': 'lambda', 'children': ['15', '17']},{'id': '15', 'type': 'lambda_parameters', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '19', 'type': 'slice', 'children': ['20', '21', '22']},{'id': '20', 'type': 'colon', 'children': []},{'id': '21', 'type': 'colon', 'children': []},{'id': '22', 'type': 'unary_operator', 'children': ['23'], 'value': '-'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'if_statement', 'children': ['25', '26', '48']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tuple_cmp'},{'id': '30', 'type': 'lambda', 'children': ['31', '33']},{'id': '31', 'type': 'lambda_parameters', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '41'], 'value': '>'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '36', 'type': 'slice', 'children': ['37', '38', '39']},{'id': '37', 'type': 'colon', 'children': []},{'id': '38', 'type': 'colon', 'children': []},{'id': '39', 'type': 'unary_operator', 'children': ['40'], 'value': '-'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'startkey'},{'id': '43', 'type': 'slice', 'children': ['44', '45', '46']},{'id': '44', 'type': 'colon', 'children': []},{'id': '45', 'type': 'colon', 'children': []},{'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tuple_cmp'},{'id': '53', 'type': 'lambda', 'children': ['54', '56']},{'id': '54', 'type': 'lambda_parameters', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '64'], 'value': '<'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '59', 'type': 'slice', 'children': ['60', '61', '62']},{'id': '60', 'type': 'colon', 'children': []},{'id': '61', 'type': 'colon', 'children': []},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'startkey'},{'id': '66', 'type': 'slice', 'children': ['67', '68', '69']},{'id': '67', 'type': 'colon', 'children': []},{'id': '68', 'type': 'colon', 'children': []},{'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '81']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'tuple_key'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'searchpos'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '89', 'type': 'generator_expression', 'children': ['90', '91']},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ifilter'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tuple_cmp'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '107'], 'value': '+'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '104', 'type': 'slice', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'searchpos'},{'id': '106', 'type': 'colon', 'children': []},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '109', 'type': 'slice', 'children': ['110', '111']},{'id': '110', 'type': 'colon', 'children': []},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'searchpos'},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'searchkeys'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'yield', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'}
def _sorted_keys(self, keys, startkey, reverse=False): tuple_key = lambda t: t[::-1] if reverse: tuple_cmp = lambda t: t[::-1] > startkey[::-1] else: tuple_cmp = lambda t: t[::-1] < startkey[::-1] searchkeys = sorted(keys, key=tuple_key, reverse=reverse) searchpos = sum(1 for _ in ifilter(tuple_cmp, searchkeys)) searchkeys = searchkeys[searchpos:] + searchkeys[:searchpos] for key in searchkeys: yield key
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stratify'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '28', '36', '72', '88', '108', '127']},{'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': 'Y'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '12', 'type': 'expression_list', 'children': ['13', '18', '23']},{'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': 'raw_data'},{'id': '17', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '22', 'type': 'string', 'children': [], 'value': "'D'"},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '27', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pscore'},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'raw_data'},{'id': '35', 'type': 'string', 'children': [], 'value': "'pscore'"},{'id': '36', 'type': 'if_statement', 'children': ['37', '44', '55']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'blocks'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'split_equal_bins'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pscore'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57', '66']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '64', 'type': 'slice', 'children': ['65']},{'id': '65', 'type': 'colon', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'function_definition', 'children': ['73', '74', '77']},{'id': '73', 'type': 'function_name', 'children': [], 'value': 'subset'},{'id': '74', 'type': 'parameters', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'p_low'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'p_high'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'binary_operator', 'children': ['80', '84'], 'value': '&'},{'id': '80', 'type': '()', 'children': ['81']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '<'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'p_low'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pscore'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '<='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pscore'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'p_high'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'subsets'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '97']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'list_splat', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'ps'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '105', 'type': 'slice', 'children': ['106', '107']},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'colon', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'strata'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '124']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'CausalModel'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '121']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'D'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '124', 'type': 'for_in_clause', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'subsets'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'strata'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'Strata'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'strata'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'subsets'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'pscore'}
def stratify(self): Y, D, X = self.raw_data['Y'], self.raw_data['D'], self.raw_data['X'] pscore = self.raw_data['pscore'] if isinstance(self.blocks, int): blocks = split_equal_bins(pscore, self.blocks) else: blocks = self.blocks[:] blocks[0] = 0 def subset(p_low, p_high): return (p_low < pscore) & (pscore <= p_high) subsets = [subset(*ps) for ps in zip(blocks, blocks[1:])] strata = [CausalModel(Y[s], D[s], X[s]) for s in subsets] self.strata = Strata(strata, subsets, pscore)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_current_orders'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '25', '28', '31', '34', '37', '40']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'bet_ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'market_ids'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'order_projection'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'customer_order_refs'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'customer_strategy_refs'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'date_range'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'time_range'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_dir'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'from_record'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'record_count'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'default_parameter', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'default_parameter', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'lightweight'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '53', '63', '76']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'clean_locals'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'},{'id': '57', 'type': 'string', 'children': [], 'value': "'%s%s'"},{'id': '58', 'type': 'tuple', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'URI'},{'id': '62', 'type': 'string', 'children': [], 'value': "'listCurrentOrders'"},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'tuple_pattern', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'process_response'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83', '86', '87']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'CurrentOrders'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'lightweight'}
def list_current_orders(self, bet_ids=None, market_ids=None, order_projection=None, customer_order_refs=None, customer_strategy_refs=None, date_range=time_range(), order_by=None, sort_dir=None, from_record=None, record_count=None, session=None, lightweight=None): params = clean_locals(locals()) method = '%s%s' % (self.URI, 'listCurrentOrders') (response, elapsed_time) = self.request(method, params, session) return self.process_response(response, resources.CurrentOrders, elapsed_time, lightweight)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'visit_Module'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '50', '92', '103', '111', '117']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'newbody'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'olddef'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '33', '41']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'FunctionDef'},{'id': '33', 'type': 'block', 'children': ['34']},{'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': 'olddef'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'newbody'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stmt'},{'id': '50', 'type': 'try_statement', 'children': ['51', '80']},{'id': '51', 'type': 'block', 'children': ['52', '64']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'newdef'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'topological_sort'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'type_dependencies'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'ordered_global_declarations'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'newdef'},{'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '72']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'newdef'},{'id': '72', 'type': 'if_clause', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'FunctionDef'},{'id': '80', 'type': 'except_clause', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'NetworkXUnfeasible'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'raise_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'PythranSyntaxError'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"Infinite function recursion"'},{'id': '92', 'type': 'assert_statement', 'children': ['93', '102']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '98'], 'value': '=='},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'newdef'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'olddef'},{'id': '102', 'type': 'string', 'children': [], 'value': '"A function have been lost..."'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'newbody'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'newdef'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '116', 'type': 'True', 'children': []},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'node'}
def visit_Module(self, node): newbody = list() olddef = list() for stmt in node.body: if isinstance(stmt, ast.FunctionDef): olddef.append(stmt) else: newbody.append(stmt) try: newdef = topological_sort( self.type_dependencies, self.ordered_global_declarations) newdef = [f for f in newdef if isinstance(f, ast.FunctionDef)] except nx.exception.NetworkXUnfeasible: raise PythranSyntaxError("Infinite function recursion") assert set(newdef) == set(olddef), "A function have been lost..." node.body = newbody + newdef self.update = True return node
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'qzordered'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'crit'},{'id': '8', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '9', 'type': 'block', 'children': ['10', '12', '16', '32', '52', '71']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '"Eigenvalues bigger than crit are sorted in the top-left."'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'TOL'},{'id': '15', 'type': 'float', 'children': [], 'value': '1e-10'},{'id': '16', 'type': 'function_definition', 'children': ['17', '18', '21']},{'id': '17', 'type': 'function_name', 'children': [], 'value': 'select'},{'id': '18', 'type': 'parameters', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '>'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '**'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '26', 'type': 'integer', 'children': [], 'value': '2'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '*'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'crit'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '**'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '31', 'type': 'integer', 'children': [], 'value': '2'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '41']},{'id': '34', 'type': 'list_pattern', 'children': ['35', '36', '37', '38', '39', '40']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ordqz'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46', '49']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '48', 'type': 'string', 'children': [], 'value': "'real'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'eigval'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '65'], 'value': '/'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'diag'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'diag'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'list', 'children': ['73', '74', '75', '76', '77'], 'value': '[S,T,U,V,eigval]'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'eigval'}
def qzordered(A,B,crit=1.0): "Eigenvalues bigger than crit are sorted in the top-left." TOL = 1e-10 def select(alpha, beta): return alpha**2>crit*beta**2 [S,T,alpha,beta,U,V] = ordqz(A,B,output='real',sort=select) eigval = abs(numpy.diag(S)/numpy.diag(T)) return [S,T,U,V,eigval]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ordqz'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'string', 'children': [], 'value': "'lhp'"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '11', 'type': 'string', 'children': [], 'value': "'real'"},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'overwrite_a'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'overwrite_b'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'check_finite'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '25', '30', '35', '44', '51', '58', '67', '71', '99', '121', '158', '165', '173', '185', '232', '236', '270', '287', '294', '323']},{'id': '22', 'type': 'import_statement', 'children': ['23']},{'id': '23', 'type': 'dotted_name', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '25', 'type': 'import_statement', 'children': ['26']},{'id': '26', 'type': 'aliased_import', 'children': ['27', '29']},{'id': '27', 'type': 'dotted_name', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '30', 'type': 'import_from_statement', 'children': ['31', '33']},{'id': '31', 'type': 'dotted_name', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '33', 'type': 'dotted_name', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'asarray_chkfinite'},{'id': '35', 'type': 'import_from_statement', 'children': ['36', '40', '42']},{'id': '36', 'type': 'dotted_name', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'misc'},{'id': '40', 'type': 'dotted_name', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'LinAlgError'},{'id': '42', 'type': 'dotted_name', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_datacopied'},{'id': '44', 'type': 'import_from_statement', 'children': ['45', '49']},{'id': '45', 'type': 'dotted_name', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'lapack'},{'id': '49', 'type': 'dotted_name', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_lapack_funcs'},{'id': '51', 'type': 'import_from_statement', 'children': ['52', '56']},{'id': '52', 'type': 'dotted_name', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_lib'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '56', 'type': 'dotted_name', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '58', 'type': 'import_from_statement', 'children': ['59', '63', '65']},{'id': '59', 'type': 'dotted_name', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_decomp_qz'},{'id': '63', 'type': 'dotted_name', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_qz'},{'id': '65', 'type': 'dotted_name', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_select_function'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_qz'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81', '84', '87', '90', '93', '96']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'B'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'overwrite_a'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'overwrite_a'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'overwrite_b'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'overwrite_b'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'check_finite'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'check_finite'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '106']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103', '104', '105']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'AA'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'BB'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '106', 'type': 'expression_list', 'children': ['107', '110', '113', '117']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '115', 'type': 'unary_operator', 'children': ['116'], 'value': '-'},{'id': '116', 'type': 'integer', 'children': [], 'value': '4'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '-'},{'id': '120', 'type': 'integer', 'children': [], 'value': '3'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125', '144']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '124', 'type': 'string', 'children': [], 'value': "'cz'"},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'pattern_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '131', 'type': 'expression_list', 'children': ['132', '141']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '+'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '135', 'type': 'integer', 'children': [], 'value': '3'},{'id': '136', 'type': 'binary_operator', 'children': ['137', '140'], 'value': '*'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '139', 'type': 'integer', 'children': [], 'value': '4'},{'id': '140', 'type': 'float', 'children': [], 'value': '1.j'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '143', 'type': 'integer', 'children': [], 'value': '5'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '151']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '151', 'type': 'expression_list', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '154', 'type': 'integer', 'children': [], 'value': '3'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '157', 'type': 'integer', 'children': [], 'value': '4'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sfunction'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_select_function'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sfunction'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '177']},{'id': '175', 'type': 'pattern_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'tgsen'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_lapack_funcs'},{'id': '179', 'type': 'argument_list', 'children': ['180', '182']},{'id': '180', 'type': 'tuple', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': "'tgsen'"},{'id': '182', 'type': 'tuple', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'AA'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'BB'},{'id': '185', 'type': 'if_statement', 'children': ['186', '194']},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '190'], 'value': 'or'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '189', 'type': 'None', 'children': []},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '192', 'type': 'unary_operator', 'children': ['193'], 'value': '-'},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'id': '194', 'type': 'block', 'children': ['195', '210', '228']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'tgsen'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202', '203', '204', '205', '206']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'AA'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'BB'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '208', 'type': 'unary_operator', 'children': ['209'], 'value': '-'},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '213', 'type': 'call', 'children': ['214', '224']},{'id': '214', 'type': 'attribute', 'children': ['215', '223']},{'id': '215', 'type': 'attribute', 'children': ['216', '222']},{'id': '216', 'type': 'subscript', 'children': ['217', '221']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '219', 'type': 'unary_operator', 'children': ['220'], 'value': '-'},{'id': '220', 'type': 'integer', 'children': [], 'value': '3'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'real'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '+='},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '231', 'type': 'integer', 'children': [], 'value': '1'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '235', 'type': 'None', 'children': []},{'id': '236', 'type': 'if_statement', 'children': ['237', '245']},{'id': '237', 'type': 'boolean_operator', 'children': ['238', '241'], 'value': 'or'},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': 'is'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '243', 'type': 'unary_operator', 'children': ['244'], 'value': '-'},{'id': '244', 'type': 'integer', 'children': [], 'value': '1'},{'id': '245', 'type': 'block', 'children': ['246', '261']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'tgsen'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253', '254', '255', '256', '257']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'AA'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'BB'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '259', 'type': 'unary_operator', 'children': ['260'], 'value': '-'},{'id': '260', 'type': 'integer', 'children': [], 'value': '1'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '264', 'type': 'subscript', 'children': ['265', '269']},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '267', 'type': 'unary_operator', 'children': ['268'], 'value': '-'},{'id': '268', 'type': 'integer', 'children': [], 'value': '2'},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'tgsen'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277', '278', '279', '280', '281', '284']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'AA'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'BB'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'Q'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'lwork'},{'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'liwork'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '292', 'type': 'unary_operator', 'children': ['293'], 'value': '-'},{'id': '293', 'type': 'integer', 'children': [], 'value': '1'},{'id': '294', 'type': 'if_statement', 'children': ['295', '298', '307']},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': '<'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '297', 'type': 'integer', 'children': [], 'value': '0'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'raise_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '%'},{'id': '304', 'type': 'string', 'children': [], 'value': '"Illegal value in argument %d of tgsen"'},{'id': '305', 'type': 'unary_operator', 'children': ['306'], 'value': '-'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '307', 'type': 'elif_clause', 'children': ['308', '311']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': '=='},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '310', 'type': 'integer', 'children': [], 'value': '1'},{'id': '311', 'type': 'block', 'children': ['312']},{'id': '312', 'type': 'raise_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'concatenated_string', 'children': ['317', '318', '319', '320', '321', '322']},{'id': '317', 'type': 'string', 'children': [], 'value': '"Reordering of (A, B) failed because the transformed"'},{'id': '318', 'type': 'string', 'children': [], 'value': '" matrix pair (A, B) would be too far from "'},{'id': '319', 'type': 'string', 'children': [], 'value': '"generalized Schur form; the problem is very "'},{'id': '320', 'type': 'string', 'children': [], 'value': '"ill-conditioned. (A, B) may have been partially "'},{'id': '321', 'type': 'string', 'children': [], 'value': '"reorded. If requested, 0 is returned in DIF(*), "'},{'id': '322', 'type': 'string', 'children': [], 'value': '"PL, and PR."'},{'id': '323', 'type': 'if_statement', 'children': ['324', '329', '360']},{'id': '324', 'type': 'comparison_operator', 'children': ['325', '326'], 'value': 'in'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '326', 'type': 'list', 'children': ['327', '328'], 'value': "['f', 'd']"},{'id': '327', 'type': 'string', 'children': [], 'value': "'f'"},{'id': '328', 'type': 'string', 'children': [], 'value': "'d'"},{'id': '329', 'type': 'block', 'children': ['330', '342']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '333', 'type': 'binary_operator', 'children': ['334', '337'], 'value': '+'},{'id': '334', 'type': 'subscript', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '336', 'type': 'integer', 'children': [], 'value': '2'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '341'], 'value': '*'},{'id': '338', 'type': 'subscript', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '340', 'type': 'integer', 'children': [], 'value': '3'},{'id': '341', 'type': 'float', 'children': [], 'value': '1.j'},{'id': '342', 'type': 'return_statement', 'children': ['343']},{'id': '343', 'type': 'tuple', 'children': ['344', '347', '350', '351', '354', '357']},{'id': '344', 'type': 'subscript', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '346', 'type': 'integer', 'children': [], 'value': '0'},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '349', 'type': 'integer', 'children': [], 'value': '1'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '351', 'type': 'subscript', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '353', 'type': 'integer', 'children': [], 'value': '4'},{'id': '354', 'type': 'subscript', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '356', 'type': 'integer', 'children': [], 'value': '5'},{'id': '357', 'type': 'subscript', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '359', 'type': 'integer', 'children': [], 'value': '6'},{'id': '360', 'type': 'else_clause', 'children': ['361']},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'return_statement', 'children': ['363']},{'id': '363', 'type': 'expression_list', 'children': ['364', '367', '370', '373', '376', '379']},{'id': '364', 'type': 'subscript', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '366', 'type': 'integer', 'children': [], 'value': '0'},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '369', 'type': 'integer', 'children': [], 'value': '1'},{'id': '370', 'type': 'subscript', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '372', 'type': 'integer', 'children': [], 'value': '2'},{'id': '373', 'type': 'subscript', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '375', 'type': 'integer', 'children': [], 'value': '3'},{'id': '376', 'type': 'subscript', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '378', 'type': 'integer', 'children': [], 'value': '4'},{'id': '379', 'type': 'subscript', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '381', 'type': 'integer', 'children': [], 'value': '5'}
def ordqz(A, B, sort='lhp', output='real', overwrite_a=False, overwrite_b=False, check_finite=True): import warnings import numpy as np from numpy import asarray_chkfinite from scipy.linalg.misc import LinAlgError, _datacopied from scipy.linalg.lapack import get_lapack_funcs from scipy._lib.six import callable from scipy.linalg._decomp_qz import _qz, _select_function lwork = None result, typ = _qz(A, B, output=output, lwork=lwork, sort=None, overwrite_a=overwrite_a, overwrite_b=overwrite_b, check_finite=check_finite) AA, BB, Q, Z = result[0], result[1], result[-4], result[-3] if typ not in 'cz': alpha, beta = result[3] + result[4]*1.j, result[5] else: alpha, beta = result[3], result[4] sfunction = _select_function(sort) select = sfunction(alpha, beta) tgsen, = get_lapack_funcs(('tgsen',), (AA, BB)) if lwork is None or lwork == -1: result = tgsen(select, AA, BB, Q, Z, lwork=-1) lwork = result[-3][0].real.astype(np.int) lwork += 1 liwork = None if liwork is None or liwork == -1: result = tgsen(select, AA, BB, Q, Z, liwork=-1) liwork = result[-2][0] result = tgsen(select, AA, BB, Q, Z, lwork=lwork, liwork=liwork) info = result[-1] if info < 0: raise ValueError("Illegal value in argument %d of tgsen" % -info) elif info == 1: raise ValueError("Reordering of (A, B) failed because the transformed" " matrix pair (A, B) would be too far from " "generalized Schur form; the problem is very " "ill-conditioned. (A, B) may have been partially " "reorded. If requested, 0 is returned in DIF(*), " "PL, and PR.") if typ in ['f', 'd']: alpha = result[2] + result[3] * 1.j return (result[0], result[1], alpha, result[4], result[5], result[6]) else: return result[0], result[1], result[2], result[3], result[4], result[5]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'inverse_cdf'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'W'},{'id': '6', 'type': 'block', 'children': ['7', '11', '17', '25', '35', '65']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'W'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '20', 'type': 'subscript', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '34', 'type': 'string', 'children': [], 'value': "'int'"},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'M'},{'id': '41', 'type': 'block', 'children': ['42', '59']},{'id': '42', 'type': 'while_statement', 'children': ['43', '48']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '>'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'su'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '48', 'type': 'block', 'children': ['49', '53']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'augmented_assignment', 'children': ['55', '56'], 'value': '+='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'W'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'A'}
def inverse_cdf(su, W): j = 0 s = W[0] M = su.shape[0] A = np.empty(M, 'int') for n in range(M): while su[n] > s: j += 1 s += W[j] A[n] = j return A
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '24', '33', '109', '125', '254', '270']},{'id': '10', 'type': 'if_statement', 'children': ['11', '22']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '21'], 'value': '=='},{'id': '12', 'type': 'call', 'children': ['13', '20']},{'id': '13', 'type': 'attribute', 'children': ['14', '19']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '18', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'string', 'children': [], 'value': "'src'"},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': []},{'id': '24', 'type': 'function_definition', 'children': ['25', '26', '28']},{'id': '25', 'type': 'function_name', 'children': [], 'value': 'alpha'},{'id': '26', 'type': 'parameters', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']},{'id': '34', 'type': 'function_name', 'children': [], 'value': 'permission'},{'id': '35', 'type': 'parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'block', 'children': ['38', '77', '86', '93', '100', '107']},{'id': '38', 'type': 'if_statement', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '40', 'type': 'block', 'children': ['41', '50', '59', '68']},{'id': '41', 'type': 'if_statement', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '=='},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'intent'},{'id': '46', 'type': 'string', 'children': [], 'value': "'in'"},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'intent'},{'id': '55', 'type': 'string', 'children': [], 'value': "'inout'"},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': "'c'"},{'id': '59', 'type': 'if_statement', 'children': ['60', '65']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'intent'},{'id': '64', 'type': 'string', 'children': [], 'value': "'out'"},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': "'d'"},{'id': '68', 'type': 'if_statement', 'children': ['69', '74']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'intent'},{'id': '73', 'type': 'string', 'children': [], 'value': "''"},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'e'"},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'perm'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'string', 'children': [], 'value': "'permission'"},{'id': '85', 'type': 'string', 'children': [], 'value': "''"},{'id': '86', 'type': 'if_statement', 'children': ['87', '90']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'perm'},{'id': '89', 'type': 'string', 'children': [], 'value': "'public'"},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'perm'},{'id': '96', 'type': 'string', 'children': [], 'value': "'protected'"},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'c'"},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'perm'},{'id': '103', 'type': 'string', 'children': [], 'value': "'private'"},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'d'"},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '109', 'type': 'function_definition', 'children': ['110', '111', '113']},{'id': '110', 'type': 'function_name', 'children': [], 'value': 'permission_alpha'},{'id': '111', 'type': 'parameters', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '122'], 'value': '+'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '+'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'permission'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '125', 'type': 'function_definition', 'children': ['126', '127', '129']},{'id': '126', 'type': 'function_name', 'children': [], 'value': 'itype'},{'id': '127', 'type': 'parameters', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'if_statement', 'children': ['131', '136', '207', '248']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '135', 'type': 'string', 'children': [], 'value': "'variable'"},{'id': '136', 'type': 'block', 'children': ['137', '143', '152', '170', '188', '205']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'vartype'},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '=='},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '146', 'type': 'string', 'children': [], 'value': "'class'"},{'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': 'retstr'},{'id': '151', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'kind'},{'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': 'retstr'},{'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '+'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '163', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '170', 'type': 'if_statement', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'strlen'},{'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': 'retstr'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '+'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '+'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '181', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'strlen'},{'id': '188', 'type': 'if_statement', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'proto'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '200'], 'value': '+'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '+'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '199', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '200', 'type': 'subscript', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'proto'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'return_statement', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'retstr'},{'id': '207', 'type': 'elif_clause', 'children': ['208', '213']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': '=='},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '212', 'type': 'string', 'children': [], 'value': "'proc'"},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'if_statement', 'children': ['215', '220', '229']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '219'], 'value': '!='},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'proctype'},{'id': '219', 'type': 'string', 'children': [], 'value': "'Function'"},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'return_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '228']},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'proctype'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'else_clause', 'children': ['230']},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'return_statement', 'children': ['232']},{'id': '232', 'type': 'binary_operator', 'children': ['233', '242'], 'value': '+'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '241'], 'value': '+'},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'proctype'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'itype'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'retvar'},{'id': '248', 'type': 'else_clause', 'children': ['249']},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '254', 'type': 'function_definition', 'children': ['255', '256', '258']},{'id': '255', 'type': 'function_name', 'children': [], 'value': 'itype_alpha'},{'id': '256', 'type': 'parameters', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'return_statement', 'children': ['260']},{'id': '260', 'type': 'binary_operator', 'children': ['261', '267'], 'value': '+'},{'id': '261', 'type': 'binary_operator', 'children': ['262', '266'], 'value': '+'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'itype'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '266', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '270', 'type': 'if_statement', 'children': ['271', '282', '292', '314', '336', '358']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '281'], 'value': '=='},{'id': '272', 'type': 'call', 'children': ['273', '280']},{'id': '273', 'type': 'attribute', 'children': ['274', '279']},{'id': '274', 'type': 'subscript', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '278', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'string', 'children': [], 'value': "'alpha'"},{'id': '282', 'type': 'block', 'children': ['283']},{'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': 'items'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '292', 'type': 'elif_clause', 'children': ['293', '304']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '303'], 'value': '=='},{'id': '294', 'type': 'call', 'children': ['295', '302']},{'id': '295', 'type': 'attribute', 'children': ['296', '301']},{'id': '296', 'type': 'subscript', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '300', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '302', 'type': 'argument_list', 'children': []},{'id': '303', 'type': 'string', 'children': [], 'value': "'permission'"},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'keyword_argument', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'permission'},{'id': '314', 'type': 'elif_clause', 'children': ['315', '326']},{'id': '315', 'type': 'comparison_operator', 'children': ['316', '325'], 'value': '=='},{'id': '316', 'type': 'call', 'children': ['317', '324']},{'id': '317', 'type': 'attribute', 'children': ['318', '323']},{'id': '318', 'type': 'subscript', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '322', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '324', 'type': 'argument_list', 'children': []},{'id': '325', 'type': 'string', 'children': [], 'value': "'permission-alpha'"},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'permission_alpha'},{'id': '336', 'type': 'elif_clause', 'children': ['337', '348']},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '347'], 'value': '=='},{'id': '338', 'type': 'call', 'children': ['339', '346']},{'id': '339', 'type': 'attribute', 'children': ['340', '345']},{'id': '340', 'type': 'subscript', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '344', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '346', 'type': 'argument_list', 'children': []},{'id': '347', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '348', 'type': 'block', 'children': ['349']},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'keyword_argument', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'itype'},{'id': '358', 'type': 'elif_clause', 'children': ['359', '370']},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '369'], 'value': '=='},{'id': '360', 'type': 'call', 'children': ['361', '368']},{'id': '361', 'type': 'attribute', 'children': ['362', '367']},{'id': '362', 'type': 'subscript', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '366', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '368', 'type': 'argument_list', 'children': []},{'id': '369', 'type': 'string', 'children': [], 'value': "'type-alpha'"},{'id': '370', 'type': 'block', 'children': ['371']},{'id': '371', 'type': 'expression_statement', 'children': ['372']},{'id': '372', 'type': 'call', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'itype_alpha'}
def sort_items(self,items,args=False): if self.settings['sort'].lower() == 'src': return def alpha(i): return i.name def permission(i): if args: if i.intent == 'in': return 'b' if i.intent == 'inout': return 'c' if i.intent == 'out': return 'd' if i.intent == '': return 'e' perm = getattr(i, 'permission', '') if perm == 'public': return 'b' if perm == 'protected': return 'c' if perm == 'private': return 'd' return 'a' def permission_alpha(i): return permission(i) + '-' + i.name def itype(i): if i.obj == 'variable': retstr = i.vartype if retstr == 'class': retstr = 'type' if i.kind: retstr = retstr + '-' + str(i.kind) if i.strlen: retstr = retstr + '-' + str(i.strlen) if i.proto: retstr = retstr + '-' + i.proto[0] return retstr elif i.obj == 'proc': if i.proctype != 'Function': return i.proctype.lower() else: return i.proctype.lower() + '-' + itype(i.retvar) else: return i.obj def itype_alpha(i): return itype(i) + '-' + i.name if self.settings['sort'].lower() == 'alpha': items.sort(key=alpha) elif self.settings['sort'].lower() == 'permission': items.sort(key=permission) elif self.settings['sort'].lower() == 'permission-alpha': items.sort(key=permission_alpha) elif self.settings['sort'].lower() == 'type': items.sort(key=itype) elif self.settings['sort'].lower() == 'type-alpha': items.sort(key=itype_alpha)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '23', '38', '53', '68', '83', '98', '113', '128', '143', '158', '173', '188', '203', '218']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Sorts components of the object.\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '14']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'string', 'children': [], 'value': "'variables'"},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'string', 'children': [], 'value': "'modules'"},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '38', 'type': 'if_statement', 'children': ['39', '44']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'string', 'children': [], 'value': "'submodules'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'submodules'},{'id': '53', 'type': 'if_statement', 'children': ['54', '59']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'string', 'children': [], 'value': "'common'"},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '68', 'type': 'if_statement', 'children': ['69', '74']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'string', 'children': [], 'value': "'subroutines'"},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'subroutines'},{'id': '83', 'type': 'if_statement', 'children': ['84', '89']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'string', 'children': [], 'value': "'modprocedures'"},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'modprocedures'},{'id': '98', 'type': 'if_statement', 'children': ['99', '104']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'string', 'children': [], 'value': "'functions'"},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '113', 'type': 'if_statement', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'string', 'children': [], 'value': "'interfaces'"},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'interfaces'},{'id': '128', 'type': 'if_statement', 'children': ['129', '134']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'string', 'children': [], 'value': "'absinterfaces'"},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'absinterfaces'},{'id': '143', 'type': 'if_statement', 'children': ['144', '149']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'string', 'children': [], 'value': "'types'"},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '158', 'type': 'if_statement', 'children': ['159', '164']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'string', 'children': [], 'value': "'programs'"},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'programs'},{'id': '173', 'type': 'if_statement', 'children': ['174', '179']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'string', 'children': [], 'value': "'blockdata'"},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'blockdata'},{'id': '188', 'type': 'if_statement', 'children': ['189', '194']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'string', 'children': [], 'value': "'boundprocs'"},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'boundprocs'},{'id': '203', 'type': 'if_statement', 'children': ['204', '209']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'string', 'children': [], 'value': "'finalprocs'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'sort_items'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'finalprocs'},{'id': '218', 'type': 'if_statement', 'children': ['219', '224']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'pass_statement', 'children': []}
def sort(self): ''' Sorts components of the object. ''' if hasattr(self,'variables'): sort_items(self,self.variables) if hasattr(self,'modules'): sort_items(self,self.modules) if hasattr(self,'submodules'): sort_items(self,self.submodules) if hasattr(self,'common'): sort_items(self,self.common) if hasattr(self,'subroutines'): sort_items(self,self.subroutines) if hasattr(self,'modprocedures'): sort_items(self,self.modprocedures) if hasattr(self,'functions'): sort_items(self,self.functions) if hasattr(self,'interfaces'): sort_items(self,self.interfaces) if hasattr(self,'absinterfaces'): sort_items(self,self.absinterfaces) if hasattr(self,'types'): sort_items(self,self.types) if hasattr(self,'programs'): sort_items(self,self.programs) if hasattr(self,'blockdata'): sort_items(self,self.blockdata) if hasattr(self,'boundprocs'): sort_items(self,self.boundprocs) if hasattr(self,'finalprocs'): sort_items(self,self.finalprocs) if hasattr(self,'args'): pass
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_catalogue_chronologically'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '16', '25', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Sorts the catalogue into chronological order\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dec_time'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_decimal_time'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dec_time'},{'id': '25', 'type': 'if_statement', 'children': ['26', '46']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '45'], 'value': '>'},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '39'], 'value': '-'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '36', 'type': 'slice', 'children': ['37', '38']},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'colon', 'children': []},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '41', 'type': 'slice', 'children': ['42', '43']},{'id': '42', 'type': 'colon', 'children': []},{'id': '43', 'type': 'unary_operator', 'children': ['44'], 'value': '-'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'float', 'children': [], 'value': '0.'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'select_catalogue_events'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'idx'}
def sort_catalogue_chronologically(self): ''' Sorts the catalogue into chronological order ''' dec_time = self.get_decimal_time() idx = np.argsort(dec_time) if np.all((idx[1:] - idx[:-1]) > 0.): return self.select_catalogue_events(idx)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmp_mat'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'block', 'children': ['7', '11', '46']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'for_statement', 'children': ['12', '15', '24']},{'id': '12', 'type': 'pattern_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '17', 'type': 'argument_list', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'flat'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'flat'},{'id': '24', 'type': 'block', 'children': ['25', '39']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '30', 'type': 'argument_list', 'children': ['31', '35']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '!='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'}
def cmp_mat(a, b): c = 0 for x, y in zip(a.flat, b.flat): c = cmp(abs(x), abs(y)) if c != 0: return c return c
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dicoms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dicoms'},{'id': '5', 'type': 'block', 'children': ['6', '24', '42', '60', '82', '104', '126', '137', '148']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_x'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dicoms'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'lambda', 'children': ['16', '18']},{'id': '16', 'type': 'lambda_parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': '()', 'children': ['19']},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_y'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dicoms'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'lambda', 'children': ['34', '36']},{'id': '34', 'type': 'lambda_parameters', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_z'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dicoms'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '51', 'type': 'lambda', 'children': ['52', '54']},{'id': '52', 'type': 'lambda_parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': '()', 'children': ['55']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '59', 'type': 'integer', 'children': [], 'value': '2'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'diff_x'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '75'], 'value': '-'},{'id': '67', 'type': 'subscript', 'children': ['68', '74']},{'id': '68', 'type': 'attribute', 'children': ['69', '73']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_x'},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'subscript', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_x'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'diff_y'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '97'], 'value': '-'},{'id': '89', 'type': 'subscript', 'children': ['90', '96']},{'id': '90', 'type': 'attribute', 'children': ['91', '95']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_y'},{'id': '93', 'type': 'unary_operator', 'children': ['94'], 'value': '-'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'subscript', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_y'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'diff_z'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'binary_operator', 'children': ['111', '119'], 'value': '-'},{'id': '111', 'type': 'subscript', 'children': ['112', '118']},{'id': '112', 'type': 'attribute', 'children': ['113', '117']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_z'},{'id': '115', 'type': 'unary_operator', 'children': ['116'], 'value': '-'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '118', 'type': 'integer', 'children': [], 'value': '2'},{'id': '119', 'type': 'subscript', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_z'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ImagePositionPatient'},{'id': '125', 'type': 'integer', 'children': [], 'value': '2'},{'id': '126', 'type': 'if_statement', 'children': ['127', '134']},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '131'], 'value': 'and'},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '>='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'diff_x'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'diff_y'},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '>='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'diff_x'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'diff_z'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_x'},{'id': '137', 'type': 'if_statement', 'children': ['138', '145']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '142'], 'value': 'and'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '>='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'diff_y'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'diff_x'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'diff_y'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'diff_z'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'return_statement', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_y'},{'id': '148', 'type': 'if_statement', 'children': ['149', '156']},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '153'], 'value': 'and'},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '>='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'diff_z'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'diff_x'},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '>='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'diff_z'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'diff_y'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dicom_input_sorted_z'}
def sort_dicoms(dicoms): dicom_input_sorted_x = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[0])) dicom_input_sorted_y = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[1])) dicom_input_sorted_z = sorted(dicoms, key=lambda x: (x.ImagePositionPatient[2])) diff_x = abs(dicom_input_sorted_x[-1].ImagePositionPatient[0] - dicom_input_sorted_x[0].ImagePositionPatient[0]) diff_y = abs(dicom_input_sorted_y[-1].ImagePositionPatient[1] - dicom_input_sorted_y[0].ImagePositionPatient[1]) diff_z = abs(dicom_input_sorted_z[-1].ImagePositionPatient[2] - dicom_input_sorted_z[0].ImagePositionPatient[2]) if diff_x >= diff_y and diff_x >= diff_z: return dicom_input_sorted_x if diff_y >= diff_x and diff_y >= diff_z: return dicom_input_sorted_y if diff_z >= diff_x and diff_z >= diff_y: return dicom_input_sorted_z
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_mosaics'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dicom_input'},{'id': '5', 'type': 'block', 'children': ['6', '21', '54']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_mosaics'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dicom_input'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'lambda', 'children': ['16', '18']},{'id': '16', 'type': 'lambda_parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'AcquisitionNumber'},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '33']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'binary_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': 'sorted_mosaics'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '48']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '41'], 'value': '>='},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted_mosaics'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'AcquisitionNumber'},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_mosaics'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '+'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'AcquisitionNumber'},{'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': 'ConversionValidationError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': '"INCONSISTENT_ACQUISITION_NUMBERS"'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted_mosaics'}
def _get_sorted_mosaics(dicom_input): sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber) for index in range(0, len(sorted_mosaics) - 1): if sorted_mosaics[index].AcquisitionNumber >= sorted_mosaics[index + 1].AcquisitionNumber: raise ConversionValidationError("INCONSISTENT_ACQUISITION_NUMBERS") return sorted_mosaics
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'relate_obs_ids_to_chosen_alts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obs_id_array'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'alt_id_array'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'choice_array'},{'id': '7', 'type': 'block', 'children': ['8', '12', '63']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'chosen_alts_to_obs_ids'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '25']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'alt_id'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'alt_id_array'},{'id': '25', 'type': 'block', 'children': ['26', '44']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'selection_condition'},{'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '40'], 'value': '&'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '=='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'alt_id_array'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'alt_id'},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'choice_array'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '49', '50']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'chosen_alts_to_obs_ids'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'alt_id'},{'id': '49', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'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': 'unique'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'obs_id_array'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'selection_condition'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'chosen_alts_to_obs_ids'}
def relate_obs_ids_to_chosen_alts(obs_id_array, alt_id_array, choice_array): chosen_alts_to_obs_ids = {} for alt_id in np.sort(np.unique(alt_id_array)): selection_condition =\ np.where((alt_id_array == alt_id) & (choice_array == 1)) chosen_alts_to_obs_ids[alt_id] =\ np.sort(np.unique(obs_id_array[selection_condition])) return chosen_alts_to_obs_ids
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_estimation_obj'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'init_vals'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ridge'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'constrained_pos'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '33', '46', '54', '71', '86']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mapping_matrices'},{'id': '22', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '23', 'type': 'conditional_expression', 'children': ['24', '29', '32'], 'value': 'if'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_mappings_for_fit'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mappings'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'zero_vector'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'init_vals'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'internal_model_name'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'display_name_to_model_type'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'model_type'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59', '60']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'estimator_class'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'current_split_func'},{'id': '59', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '60', 'type': 'tuple', 'children': ['61', '66']},{'id': '61', 'type': 'subscript', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'model_type_to_resources'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'internal_model_name'},{'id': '65', 'type': 'string', 'children': [], 'value': "'estimator'"},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'model_type_to_resources'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'internal_model_name'},{'id': '70', 'type': 'string', 'children': [], 'value': "'split_func'"},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'estimation_obj'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'estimator_class'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '80', '81', '82', '83']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'model_obj'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'mapping_matrices'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ridge'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'zero_vector'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_split_func'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'constrained_pos'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'estimation_obj'}
def create_estimation_obj(model_obj, init_vals, mappings=None, ridge=None, constrained_pos=None, weights=None): mapping_matrices =\ model_obj.get_mappings_for_fit() if mappings is None else mappings zero_vector = np.zeros(init_vals.shape[0]) internal_model_name = display_name_to_model_type[model_obj.model_type] estimator_class, current_split_func =\ (model_type_to_resources[internal_model_name]['estimator'], model_type_to_resources[internal_model_name]['split_func']) estimation_obj = estimator_class(model_obj, mapping_matrices, ridge, zero_vector, current_split_func, constrained_pos, weights=weights) return estimation_obj
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sequence'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '110']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n sort the points in the line with given option\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '20']},{'id': '9', 'type': '()', 'children': ['10']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '19'], 'value': '=='},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'integer', 'children': [], 'value': '2'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '34', '60', '99']},{'id': '22', 'type': '()', 'children': ['23']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '29'], 'value': 'or'},{'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': 'Sort'},{'id': '28', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '33', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '34', 'type': 'block', 'children': ['35', '51']},{'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': 'Points'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'lambda', 'children': ['46', '48']},{'id': '46', 'type': 'lambda_parameters', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '73']},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '68'], 'value': 'or'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '67', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '=='},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '72', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '73', 'type': 'block', 'children': ['74', '90']},{'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': 'Points'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '84', 'type': 'lambda', 'children': ['85', '87']},{'id': '85', 'type': 'lambda_parameters', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '110', 'type': 'if_statement', 'children': ['111', '122']},{'id': '111', 'type': '()', 'children': ['112']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '121'], 'value': '=='},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'subscript', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'integer', 'children': [], 'value': '3'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'if_statement', 'children': ['124', '136', '162', '201', '240']},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '131'], 'value': 'or'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '130', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '135', 'type': 'string', 'children': [], 'value': "'x'"},{'id': '136', 'type': 'block', 'children': ['137', '153']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'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': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '147', 'type': 'lambda', 'children': ['148', '150']},{'id': '148', 'type': 'lambda_parameters', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '162', 'type': 'elif_clause', 'children': ['163', '175']},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '170'], 'value': 'or'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '=='},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '169', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '174', 'type': 'string', 'children': [], 'value': "'y'"},{'id': '175', 'type': 'block', 'children': ['176', '192']},{'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': 'Points'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '186', 'type': 'lambda', 'children': ['187', '189']},{'id': '187', 'type': 'lambda_parameters', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '201', 'type': 'elif_clause', 'children': ['202', '214']},{'id': '202', 'type': '()', 'children': ['203']},{'id': '203', 'type': 'boolean_operator', 'children': ['204', '209'], 'value': 'or'},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '208'], 'value': '=='},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '208', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '213'], 'value': '=='},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'Sort'},{'id': '213', 'type': 'string', 'children': [], 'value': "'Z'"},{'id': '214', 'type': 'block', 'children': ['215', '231']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '225', 'type': 'lambda', 'children': ['226', '228']},{'id': '226', 'type': 'lambda_parameters', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '230', 'type': 'integer', 'children': [], 'value': '2'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'Points'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'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': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'Points'}
def sequence(self): ''' sort the points in the line with given option ''' if (len(self.Points[0]) == 2): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) else: self.order(self.Points) if (len(self.Points[0]) == 3): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) elif (self.Sort == 'Z' or self.Sort == 'Z'): self.Points.sort(key=lambda x: x[2]) self.order(self.Points) else: self.order(self.Points)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_pos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '12', 'type': 'argument_list', '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': 'runtime'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_keys'},{'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': 'hashi'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'if_statement', 'children': ['25', '35', '38']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'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': 'runtime'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_keys'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'else_clause', 'children': ['39']},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'p'}
def _get_pos(self, key): p = bisect(self.runtime._keys, self.hashi(key)) if p == len(self.runtime._keys): return 0 else: return p
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lapmod'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'fast'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'return_cost'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fp_version'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'FP_DYNAMIC'},{'id': '17', 'type': 'block', 'children': ['18', '26', '255']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'check_cost'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24', '25']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '46']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'fast'},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_lapmod'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41', '42', '43']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fp_version'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'fp_version'},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48', '62', '76', '90', '105', '120', '135', '150', '164', '192', '242']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'float64'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '97', 'type': 'argument_list', 'children': ['98', '100']},{'id': '98', 'type': 'tuple', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '112', 'type': 'argument_list', 'children': ['113', '115']},{'id': '113', 'type': 'tuple', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '127', 'type': 'argument_list', 'children': ['128', '130']},{'id': '128', 'type': 'tuple', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'float64'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'free_rows'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '142', 'type': 'argument_list', 'children': ['143', '145']},{'id': '143', 'type': 'tuple', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'int32'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_pycrrt'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158', '159', '160', '161', '162', '163']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'free_rows'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '164', 'type': 'if_statement', 'children': ['165', '168']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '=='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '167', 'type': 'integer', 'children': [], 'value': '0'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'if_statement', 'children': ['170', '173', '186']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'is'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'return_cost'},{'id': '172', 'type': 'True', 'children': []},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'expression_list', 'children': ['176', '184', '185']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'get_cost'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181', '182', '183']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '186', 'type': 'else_clause', 'children': ['187']},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'return_statement', 'children': ['189']},{'id': '189', 'type': 'expression_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '192', 'type': 'for_statement', 'children': ['193', '194', '198']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'it'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'integer', 'children': [], 'value': '2'},{'id': '198', 'type': 'block', 'children': ['199', '214']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_pyarr'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208', '209', '210', '211', '212', '213']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'free_rows'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '214', 'type': 'if_statement', 'children': ['215', '218']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'if_statement', 'children': ['220', '223', '236']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'is'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'return_cost'},{'id': '222', 'type': 'True', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'return_statement', 'children': ['225']},{'id': '225', 'type': 'expression_list', 'children': ['226', '234', '235']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get_cost'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231', '232', '233']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '236', 'type': 'else_clause', 'children': ['237']},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'expression_list', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_pya'},{'id': '245', 'type': 'argument_list', 'children': ['246', '247', '248', '249', '250', '251', '252', '253', '254']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'n_free_rows'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'free_rows'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '255', 'type': 'if_statement', 'children': ['256', '259', '272']},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': 'is'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'return_cost'},{'id': '258', 'type': 'True', 'children': []},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'return_statement', 'children': ['261']},{'id': '261', 'type': 'expression_list', 'children': ['262', '270', '271']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'get_cost'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266', '267', '268', '269']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ii'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'kk'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '272', 'type': 'else_clause', 'children': ['273']},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'expression_list', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'y'}
def lapmod(n, cc, ii, kk, fast=True, return_cost=True, fp_version=FP_DYNAMIC): check_cost(n, cc, ii, kk) if fast is True: x, y = _lapmod(n, cc, ii, kk, fp_version=fp_version) else: cc = np.ascontiguousarray(cc, dtype=np.float64) ii = np.ascontiguousarray(ii, dtype=np.int32) kk = np.ascontiguousarray(kk, dtype=np.int32) x = np.empty((n,), dtype=np.int32) y = np.empty((n,), dtype=np.int32) v = np.empty((n,), dtype=np.float64) free_rows = np.empty((n,), dtype=np.int32) n_free_rows = _pycrrt(n, cc, ii, kk, free_rows, x, y, v) if n_free_rows == 0: if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y for it in range(2): n_free_rows = _pyarr( n, cc, ii, kk, n_free_rows, free_rows, x, y, v) if n_free_rows == 0: if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y _pya(n, cc, ii, kk, n_free_rows, free_rows, x, y, v) if return_cost is True: return get_cost(n, cc, ii, kk, x), x, y else: return x, y
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_items'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'block', 'children': ['6', '10', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '13', 'type': 'block', 'children': ['14', '23', '39']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lookup'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '21', 'type': 'string', 'children': [], 'value': "'itemCategory'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'categoryCode'"},{'id': '23', 'type': 'if_statement', 'children': ['24', '32']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '31'], 'value': 'is'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '38', 'type': 'list', 'children': [], 'value': '[]'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_items'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted_items'}
def sort_items(items): sorted_items = {} for item in items: category = lookup(item, 'itemCategory', 'categoryCode') if sorted_items.get(category) is None: sorted_items[category] = [] sorted_items[category].append(item) return sorted_items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_user_permissions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '6', 'type': 'block', 'children': ['7', '20']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'permissions'},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'user_service'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getPermissions'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'user_id'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'permissions'},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'keyName'"}
def get_user_permissions(self, user_id): permissions = self.user_service.getPermissions(id=user_id) return sorted(permissions, key=itemgetter('keyName'))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'transformChildrenToNative'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '21']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'childArray'},{'id': '8', 'type': 'generator_expression', 'children': ['9', '14']},{'id': '9', 'type': 'subscript', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'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': 'sortChildKeys'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'childArray'},{'id': '25', 'type': 'block', 'children': ['26', '34']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'transformToNative'},{'id': '33', 'type': 'argument_list', 'children': []},{'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': 'child'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'transformChildrenToNative'},{'id': '39', 'type': 'argument_list', 'children': []}
def transformChildrenToNative(self): for childArray in (self.contents[k] for k in self.sortChildKeys()): for child in childArray: child = child.transformToNative() child.transformChildrenToNative()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_candidate_pairs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ice_controlling'},{'id': '6', 'type': 'block', 'children': ['7', '24']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'pair_priority'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'candidate_pair_priority'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20', '23']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'local_candidate'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'remote_candidate'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ice_controlling'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pair_priority'}
def sort_candidate_pairs(pairs, ice_controlling): def pair_priority(pair): return -candidate_pair_priority(pair.local_candidate, pair.remote_candidate, ice_controlling) pairs.sort(key=pair_priority)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_by_refs'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '5', 'type': 'block', 'children': ['6', '23', '35']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'topology'},{'id': '9', 'type': 'dictionary_comprehension', 'children': ['10', '20']},{'id': '10', 'type': 'pair', 'children': ['11', '14']},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '13', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '19', 'type': 'string', 'children': [], 'value': "'refs'"},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'by_name'},{'id': '26', 'type': 'dictionary_comprehension', 'children': ['27', '32']},{'id': '27', 'type': 'pair', 'children': ['28', '31']},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '30', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'list_comprehension', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'by_name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'toposort_flatten'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'topology'}
def order_by_refs(envs): topology = { env['name']: set(env['refs']) for env in envs } by_name = { env['name']: env for env in envs } return [ by_name[name] for name in toposort_flatten(topology) ]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merged_packages'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'env_packages'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '6', 'type': 'block', 'children': ['7', '30', '34', '40', '78', '111']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'combined_packages'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '19', 'type': 'generator_expression', 'children': ['20', '27']},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'env_packages'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '33', 'type': 'dictionary', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '45']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'combined_packages'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'if_statement', 'children': ['47', '50', '70']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'if_statement', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '!='},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'tuple', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '78', 'type': 'if_statement', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '80', 'type': 'block', 'children': ['81', '106']},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '87']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97', '100', '103']},{'id': '94', 'type': 'concatenated_string', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"Package %s was resolved to different "'},{'id': '96', 'type': 'string', 'children': [], 'value': '"versions in different environments: %s and %s"'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '105', 'type': 'integer', 'children': [], 'value': '2'},{'id': '106', 'type': 'raise_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': '"Please add constraints for the package version listed above"'},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'result'}
def merged_packages(env_packages, names): combined_packages = sorted(itertools.chain.from_iterable( env_packages[name].items() for name in names )) result = {} errors = set() for name, version in combined_packages: if name in result: if result[name] != version: errors.add((name, version, result[name])) else: result[name] = version if errors: for error in sorted(errors): logger.error( "Package %s was resolved to different " "versions in different environments: %s and %s", error[0], error[1], error[2], ) raise RuntimeError( "Please add constraints for the package version listed above" ) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recursive_refs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'block', 'children': ['7', '24', '30', '63']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'refs_by_name'},{'id': '10', 'type': 'dictionary_comprehension', 'children': ['11', '21']},{'id': '11', 'type': 'pair', 'children': ['12', '15']},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '14', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '20', 'type': 'string', 'children': [], 'value': "'refs'"},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'refs_by_name'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'if_statement', 'children': ['31', '32', '55']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'refs'},{'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': 'indirect_refs'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '52']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'recursive_refs'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'indirect_refs'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'refs'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'indirect_refs'}
def recursive_refs(envs, name): refs_by_name = { env['name']: set(env['refs']) for env in envs } refs = refs_by_name[name] if refs: indirect_refs = set(itertools.chain.from_iterable([ recursive_refs(envs, ref) for ref in refs ])) else: indirect_refs = set() return set.union(refs, indirect_refs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reference_cluster'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'block', 'children': ['7', '27', '41', '83']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '19', '22']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'list', 'children': ['15', '18'], 'value': "[env['name'], ref]"},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '17', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'envs'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '26', 'type': 'string', 'children': [], 'value': "'refs'"},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '32', 'type': 'expression_list', 'children': ['33', '36']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'list', 'children': ['40'], 'value': '[name]'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'while_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '!='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '45', 'type': 'block', 'children': ['46', '53', '57', '79']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '56', 'type': 'list', 'children': [], 'value': '[]'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'if_statement', 'children': ['62', '65', '70']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '&'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'augmented_assignment', 'children': ['68', '69'], 'value': '|='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'to_visit'},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'cluster'}
def reference_cluster(envs, name): edges = [ set([env['name'], ref]) for env in envs for ref in env['refs'] ] prev, cluster = set(), set([name]) while prev != cluster: prev = set(cluster) to_visit = [] for edge in edges: if cluster & edge: cluster |= edge else: to_visit.append(edge) edges = to_visit return cluster
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '11', 'type': 'integer', 'children': [], 'value': '100'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'aquarius_url'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '24', '31']},{'id': '19', 'type': 'assert_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '>='},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'string', 'children': [], 'value': "f'Invalid page value {page}. Required page >= 1.'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "f'Searching asset containing: {text}'"},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'list_comprehension', 'children': ['33', '39']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'DDO'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ddo_dict'},{'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ddo_dict'},{'id': '41', 'type': 'subscript', 'children': ['42', '56']},{'id': '42', 'type': 'call', 'children': ['43', '51']},{'id': '43', 'type': 'attribute', 'children': ['44', '50']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_get_aquarius'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'aquarius_url'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'text_search'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '54', '55']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '56', 'type': 'string', 'children': [], 'value': "'results'"}
def search(self, text, sort=None, offset=100, page=1, aquarius_url=None): assert page >= 1, f'Invalid page value {page}. Required page >= 1.' logger.info(f'Searching asset containing: {text}') return [DDO(dictionary=ddo_dict) for ddo_dict in self._get_aquarius(aquarius_url).text_search(text, sort, offset, page)['results']]