sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_entries'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'chemsys_formula_id_criteria'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'compatible_only'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'inc_structure'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'property_data'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'conventional_unit_cell'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_by_e_above_hull'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '32', '41', '67', '74', '98', '121', '131', '135', '320', '342', '362']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '25', 'type': 'list', 'children': ['26', '27', '28', '29', '30', '31'], 'value': '["run_type", "is_hubbard", "pseudo_potential", "hubbards",\n "potcar_symbols", "oxide_type"]'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"run_type"'}, {'id': '27', 'type': 'string', 'children': [], 'value': '"is_hubbard"'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"pseudo_potential"'}, {'id': '29', 'type': 'string', 'children': [], 'value': '"hubbards"'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"potcar_symbols"'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"oxide_type"'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '35', 'type': 'binary_operator', 'children': ['36', '40'], 'value': '+'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39'], 'value': '["energy", "unit_cell_formula", "task_id"]'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"energy"'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"unit_cell_formula"'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"task_id"'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort_by_e_above_hull'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50', '58']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '47'], 'value': 'and'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'property_data'}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"e_above_hull"'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'property_data'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'property_data'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'string', 'children': [], 'value': '"e_above_hull"'}; {'id': '58', 'type': 'elif_clause', 'children': ['59', '61']}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'property_data'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'property_data'}, {'id': '65', 'type': 'list', 'children': ['66'], 'value': '["e_above_hull"]'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"e_above_hull"'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'property_data'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'augmented_assignment', 'children': ['72', '73'], 'value': '+='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'property_data'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'inc_structure'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81', '89']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'inc_structure'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"initial"'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"initial_structure"'}, {'id': '89', 'type': 'else_clause', 'children': ['90']}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'string', 'children': [], 'value': '"structure"'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '105', '115']}, {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'chemsys_formula_id_criteria'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'criteria'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'MPRester'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'parse_criteria'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'chemsys_formula_id_criteria'}, {'id': '115', 'type': 'else_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'criteria'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'chemsys_formula_id_criteria'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'criteria'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '134', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '135', 'type': 'for_statement', 'children': ['136', '137', '138']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '138', 'type': 'block', 'children': ['139', '161', '170', '188', '313']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '143', 'type': 'string', 'children': [], 'value': '"potcar_symbols"'}; {'id': '144', 'type': 'list_comprehension', 'children': ['145', '154']}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"%s %s"'}, {'id': '147', 'type': 'tuple', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '151', 'type': 'string', 'children': [], 'value': '"pseudo_potential"'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"functional"'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '156', 'type': 'subscript', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"pseudo_potential"'}; {'id': '160', 'type': 'string', 'children': [], 'value': '"labels"'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '164', 'type': 'dictionary', 'children': ['165']}, {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"oxide_type"'}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '169', 'type': 'string', 'children': [], 'value': '"oxide_type"'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'property_data'}; {'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': 'data'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'dictionary_comprehension', 'children': ['180', '185']}; {'id': '180', 'type': 'pair', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '185', 'type': 'for_in_clause', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'property_data'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '191', '223']}, {'id': '189', 'type': 'not_operator', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'inc_structure'}, {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ComputedEntry'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '201', '204', '215', '218']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '200', 'type': 'string', 'children': [], 'value': '"unit_cell_formula"'}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '203', 'type': 'string', 'children': [], 'value': '"energy"'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '206', 'type': 'dictionary_comprehension', 'children': ['207', '212']}, {'id': '207', 'type': 'pair', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '212', 'type': 'for_in_clause', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'entry_id'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '222', 'type': 'string', 'children': [], 'value': '"task_id"'}, {'id': '223', 'type': 'else_clause', 'children': ['224']}; {'id': '224', 'type': 'block', 'children': ['225', '239', '286']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'prim'}; {'id': '228', 'type': 'conditional_expression', 'children': ['229', '232', '235', '236'], 'value': 'if'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"initial_structure"'}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': '=='}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'inc_structure'}; {'id': '234', 'type': 'string', 'children': [], 'value': '"initial"'}, {'id': '235', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '238', 'type': 'string', 'children': [], 'value': '"structure"'}, {'id': '239', 'type': 'if_statement', 'children': ['240', '241', '270']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'conventional_unit_cell'}, {'id': '241', 'type': 'block', 'children': ['242', '253']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '245', 'type': 'call', 'children': ['246', '252']}; {'id': '246', 'type': 'attribute', 'children': ['247', '251']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'SpacegroupAnalyzer'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'prim'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'get_conventional_standard_structure'}; {'id': '252', 'type': 'argument_list', 'children': []}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'energy'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '260'], 'value': '*'}, {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '259', 'type': 'string', 'children': [], 'value': '"energy"'}; {'id': '260', 'type': 'parenthesized_expression', 'children': ['261']}, {'id': '261', 'type': 'binary_operator', 'children': ['262', '266'], 'value': '/'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'prim'}; {'id': '270', 'type': 'else_clause', 'children': ['271']}, {'id': '271', 'type': 'block', 'children': ['272', '280']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'prim'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '279', 'type': 'argument_list', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'energy'}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '285', 'type': 'string', 'children': [], 'value': '"energy"'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ComputedStructureEntry'}, {'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '305', '308']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'energy'}; {'id': '294', 'type': 'keyword_argument', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '296', 'type': 'dictionary_comprehension', 'children': ['297', '302']}, {'id': '297', 'type': 'pair', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '302', 'type': 'for_in_clause', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '305', 'type': 'keyword_argument', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'entry_id'}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '312', 'type': 'string', 'children': [], 'value': '"task_id"'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'call', 'children': ['315', '318']}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '320', 'type': 'if_statement', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'compatible_only'}; {'id': '322', 'type': 'block', 'children': ['323', '331']}, {'id': '323', 'type': 'import_from_statement', 'children': ['324', '328', '329']}; {'id': '324', 'type': 'dotted_name', 'children': ['325', '326', '327']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'pymatgen'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'compatibility'}; {'id': '328', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '329', 'type': 'dotted_name', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'MaterialsProjectCompatibility'}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '334', 'type': 'call', 'children': ['335', '340']}, {'id': '335', 'type': 'attribute', 'children': ['336', '339']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'MaterialsProjectCompatibility'}; {'id': '338', 'type': 'argument_list', 'children': []}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'process_entries'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '342', 'type': 'if_statement', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'sort_by_e_above_hull'}; {'id': '344', 'type': 'block', 'children': ['345']}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '350', 'type': 'argument_list', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '354', 'type': 'lambda', 'children': ['355', '357']}, {'id': '355', 'type': 'lambda_parameters', 'children': ['356']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '357', 'type': 'subscript', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '361', 'type': 'string', 'children': [], 'value': '"e_above_hull"'}; {'id': '362', 'type': 'return_statement', 'children': ['363']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'entries'}
def get_entries(self, chemsys_formula_id_criteria, compatible_only=True, inc_structure=None, property_data=None, conventional_unit_cell=False, sort_by_e_above_hull=False): params = ["run_type", "is_hubbard", "pseudo_potential", "hubbards", "potcar_symbols", "oxide_type"] props = ["energy", "unit_cell_formula", "task_id"] + params if sort_by_e_above_hull: if property_data and "e_above_hull" not in property_data: property_data.append("e_above_hull") elif not property_data: property_data = ["e_above_hull"] if property_data: props += property_data if inc_structure: if inc_structure == "initial": props.append("initial_structure") else: props.append("structure") if not isinstance(chemsys_formula_id_criteria, dict): criteria = MPRester.parse_criteria(chemsys_formula_id_criteria) else: criteria = chemsys_formula_id_criteria data = self.query(criteria, props) entries = [] for d in data: d["potcar_symbols"] = [ "%s %s" % (d["pseudo_potential"]["functional"], l) for l in d["pseudo_potential"]["labels"]] data = {"oxide_type": d["oxide_type"]} if property_data: data.update({k: d[k] for k in property_data}) if not inc_structure: e = ComputedEntry(d["unit_cell_formula"], d["energy"], parameters={k: d[k] for k in params}, data=data, entry_id=d["task_id"]) else: prim = d["initial_structure"] if inc_structure == "initial" \ else d["structure"] if conventional_unit_cell: s = SpacegroupAnalyzer(prim).get_conventional_standard_structure() energy = d["energy"] * (len(s) / len(prim)) else: s = prim.copy() energy = d["energy"] e = ComputedStructureEntry( s, energy, parameters={k: d[k] for k in params}, data=data, entry_id=d["task_id"]) entries.append(e) if compatible_only: from pymatgen.entries.compatibility import \ MaterialsProjectCompatibility entries = MaterialsProjectCompatibility().process_entries(entries) if sort_by_e_above_hull: entries = sorted(entries, key=lambda entry: entry.data["e_above_hull"]) return entries
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'aos_as_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Returns a list of atomic orbitals, sorted from lowest to highest energy\n '''"}; {'id': '8', 'type': 'return_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '37']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'chain'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'from_iterable'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '32']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '24'], 'value': '*'}, {'id': '19', 'type': 'subscript', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'aos'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'composition'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'elements'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '39', 'type': 'lambda', 'children': ['40', '42']}; {'id': '40', 'type': 'lambda_parameters', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'}
def aos_as_list(self): ''' Returns a list of atomic orbitals, sorted from lowest to highest energy ''' return sorted(chain.from_iterable( [self.aos[el] * int(self.composition[el]) for el in self.elements] ), key=lambda x: x[2])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dataframe'}, {'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': 'sort_key'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"wall_time"'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '16', '29', '54', '62', '70', '78', '86', '94', '102', '110']}, {'id': '11', 'type': 'import_statement', 'children': ['12']}; {'id': '12', 'type': 'aliased_import', 'children': ['13', '15']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pandas'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'AbinitTimerSection'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'FIELDS'}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '37']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'osect'}, {'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': 'order_sections'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '51']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'osect'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ignore_index'}, {'id': '53', 'type': 'True', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cpu_time'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cpu_time'}; {'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': 'frame'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'wall_time'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'wall_time'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'mpi_nprocs'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'mpi_nprocs'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'omp_nthreads'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'omp_nthreads'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'mpi_rank'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'mpi_rank'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'fname'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'frame'}
def get_dataframe(self, sort_key="wall_time", **kwargs): import pandas as pd frame = pd.DataFrame(columns=AbinitTimerSection.FIELDS) for osect in self.order_sections(sort_key): frame = frame.append(osect.to_dict(), ignore_index=True) frame.info = self.info frame.cpu_time = self.cpu_time frame.wall_time = self.wall_time frame.mpi_nprocs = self.mpi_nprocs frame.omp_nthreads = self.omp_nthreads frame.mpi_rank = self.mpi_rank frame.fname = self.fname return frame
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_sections'}, {'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': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fsort'}, {'id': '13', 'type': 'lambda', 'children': ['14', '16']}; {'id': '14', 'type': 'lambda_parameters', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28', '31']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fsort'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def order_sections(self, key, reverse=True): fsort = lambda s: s.__dict__[key] return sorted(self.sections, key=fsort, reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '24', '60']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kv_items'}, {'id': '15', 'type': 'list_comprehension', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kv'}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kv'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28', '46']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'kv_items'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '43']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}, {'id': '47', 'type': 'block', 'children': ['48']}; {'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': 'kv_items'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57']}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}
def sort_dict(d, key=None, reverse=False): kv_items = [kv for kv in d.items()] if key is None: kv_items.sort(key=lambda t: t[1], reverse=reverse) else: kv_items.sort(key=key, reverse=reverse) return collections.OrderedDict(kv_items)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_efficiency'}, {'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': 'reverse'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '28']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_confs'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '25']}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'lambda', 'children': ['20', '22']}; {'id': '20', 'type': 'lambda_parameters', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'efficiency'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort_by_efficiency(self, reverse=True): self._confs.sort(key=lambda c: c.efficiency, reverse=reverse) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_speedup'}, {'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': 'reverse'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '28']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_confs'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '25']}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'lambda', 'children': ['20', '22']}; {'id': '20', 'type': 'lambda_parameters', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'speedup'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort_by_speedup(self, reverse=True): self._confs.sort(key=lambda c: c.speedup, reverse=reverse) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_mem_per_proc'}, {'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': 'reverse'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '41']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '21']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '12', 'type': 'generator_expression', 'children': ['13', '18']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '17'], 'value': '>'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'mem_per_proc'}, {'id': '17', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_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': '_confs'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '38']}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mem_per_proc'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '41', 'type': 'return_statement', 'children': ['42']}
def sort_by_mem_per_proc(self, reverse=False): if any(c.mem_per_proc > 0.0 for c in self): self._confs.sort(key=lambda c: c.mem_per_proc, reverse=reverse) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_cohp_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cohp_dict'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'key_sort_func'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '37']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '12', '27']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key_sort_func'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '24']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cohp_dict'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key_sort_func'}, {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cohp_dict'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'add_cohp'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cohp_dict'}
def add_cohp_dict(self, cohp_dict, key_sort_func=None): if key_sort_func: keys = sorted(cohp_dict.keys(), key=key_sort_func) else: keys = cohp_dict.keys() for label in keys: self.add_cohp(label, cohp_dict[label])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_line_in_facet'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'facet'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20', '24', '125']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'facet'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'outer_lines'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pt'}, {'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': 'prev'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'while_statement', 'children': ['25', '31']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': '>'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'block', 'children': ['32', '85', '102', '119']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36', '46']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'prev'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'for_statement', 'children': ['49', '52', '56']}, {'id': '49', 'type': 'pattern_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'prev'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '61', 'type': 'block', 'children': ['62', '71', '84']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '77']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '76'], 'value': '=='}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'prev'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'break_statement', 'children': []}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pt'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '101']}; {'id': '92', 'type': 'attribute', 'children': ['93', '100']}, {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'wulff_pt_list'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'tolist'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pt'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '118']}, {'id': '109', 'type': 'attribute', 'children': ['110', '117']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'wulff_pt_list'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'prev'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'return_statement', 'children': ['126']}
def get_line_in_facet(self, facet): lines = list(facet.outer_lines) pt = [] prev = None while len(lines) > 0: if prev is None: l = lines.pop(0) else: for i, l in enumerate(lines): if prev in l: l = lines.pop(i) if l[1] == prev: l.reverse() break pt.append(self.wulff_pt_list[l[0]].tolist()) pt.append(self.wulff_pt_list[l[1]].tolist()) prev = l[1] return pt
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_classical_addresses_from_program'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'program'}, {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'generic_type', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '8', 'type': 'type_parameter', 'children': ['9', '11']}, {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '14', 'type': 'type_parameter', 'children': ['15']}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'block', 'children': ['18', '37', '41', '73', '105']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21', '33']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'addresses'}, {'id': '21', 'type': 'type', 'children': ['22']}; {'id': '22', 'type': 'generic_type', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '24', 'type': 'type_parameter', 'children': ['25', '27']}, {'id': '25', 'type': 'type', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'generic_type', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '30', 'type': 'type_parameter', 'children': ['31']}, {'id': '31', 'type': 'type', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'flattened_addresses'}; {'id': '40', 'type': 'dictionary', 'children': []}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'program'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '55']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '52'], 'value': 'and'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Measurement'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'classical_reg'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '67']}; {'id': '58', 'type': 'attribute', 'children': ['59', '66']}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'addresses'}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'classical_reg'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'classical_reg'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '77', '82']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'addresses'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83', '93', '99']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'reduced_list'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'v'}, {'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': 'reduced_list'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'flattened_addresses'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'reduced_list'}, {'id': '105', 'type': 'return_statement', 'children': ['106']}
def get_classical_addresses_from_program(program) -> Dict[str, List[int]]: addresses: Dict[str, List[int]] = defaultdict(list) flattened_addresses = {} for instr in program: if isinstance(instr, Measurement) and instr.classical_reg: addresses[instr.classical_reg.name].append(instr.classical_reg.offset) for k, v in addresses.items(): reduced_list = list(set(v)) reduced_list.sort() flattened_addresses[k] = reduced_list return flattened_addresses
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'percolate_declares'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'program'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Program'}; {'id': '8', 'type': 'type', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Program'}; {'id': '10', 'type': 'block', 'children': ['11', '17', '23', '44', '50', '58']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'declare_program'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Program'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'instrs_program'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Program'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'instr'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'program'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '33', '38']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Declare'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'augmented_assignment', 'children': ['36', '37'], 'value': '+='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'declare_program'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'augmented_assignment', 'children': ['42', '43'], 'value': '+='}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'instrs_program'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'instr'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'declare_program'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'instrs_program'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_defined_gates'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'program'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_defined_gates'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'}
def percolate_declares(program: Program) -> Program: declare_program = Program() instrs_program = Program() for instr in program: if isinstance(instr, Declare): declare_program += instr else: instrs_program += instr p = declare_program + instrs_program p._defined_gates = program._defined_gates return p
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'text_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '6', 'type': 'keyword_separator', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'english'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'diacritic_sensitive'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'text_score'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '24', 'type': 'None', 'children': []}, {'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': 'OperationError'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'concatenated_string', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'This query is only supported when running '"}
def text_search(conn, search, *, language='english', case_sensitive=False, diacritic_sensitive=False, text_score=False, limit=0, table=None): raise OperationError('This query is only supported when running ' 'BigchainDB with MongoDB as the backend.')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_utxoset_merkle_root'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '19', '48']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'utxoset'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'backend'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_unspent_outputs'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hashes'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '45']}, {'id': '23', 'type': 'call', 'children': ['24', '44']}; {'id': '24', 'type': 'attribute', 'children': ['25', '43']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sha3_256'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '42']}, {'id': '29', 'type': 'attribute', 'children': ['30', '41']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'{}{}'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'utxo'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'transaction_id'"}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'utxo'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'output_index'"}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'digest'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'utxo'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'utxoset'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'merkleroot'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'hashes'}
def get_utxoset_merkle_root(self): utxoset = backend.query.get_unspent_outputs(self.connection) hashes = [ sha3_256( '{}{}'.format(utxo['transaction_id'], utxo['output_index']).encode() ).digest() for utxo in utxoset ] return merkleroot(sorted(hashes))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_time'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Callable'}, {'id': '9', 'type': 'type_parameter', 'children': ['10', '12']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'ellipsis', 'children': [], 'value': '...'}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'generic_type', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Callable'}, {'id': '17', 'type': 'type_parameter', 'children': ['18', '20']}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'ellipsis', 'children': [], 'value': '...'}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '22', 'type': 'block', 'children': ['23', '96']}, {'id': '23', 'type': 'function_definition', 'children': ['24', '25', '30']}; {'id': '24', 'type': 'function_name', 'children': [], 'value': 'wrapper'}, {'id': '25', 'type': 'parameters', 'children': ['26', '28']}; {'id': '26', 'type': 'list_splat_pattern', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '28', 'type': 'dictionary_splat_pattern', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'block', 'children': ['31', '39', '53', '63', '94']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'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': 'log'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"%s starting..."'}; {'id': '46', 'type': 'call', 'children': ['47', '52']}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'title'}; {'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': 'ret'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '61']}, {'id': '59', 'type': 'list_splat', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '61', 'type': 'dictionary_splat', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'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': 'log'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '77']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"%s finished (%s)"'}; {'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': 'func'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'seconds'}; {'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', '93'], 'value': '-'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'wrapper'}
def log_time(func: Callable[..., Any]) -> Callable[..., Any]: def wrapper(*args, **kwargs): start_time = time.time() log.info("%s starting...", func.__name__.title()) ret = func(*args, **kwargs) log.info( "%s finished (%s)", func.__name__.title(), datetime.timedelta(seconds=int(time.time() - start_time)), ) return ret return wrapper
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_mro'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'block', 'children': ['6', '22']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '14']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '13'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'platform'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'python_implementation'}; {'id': '12', 'type': 'argument_list', 'children': []}, {'id': '13', 'type': 'string', 'children': [], 'value': '"Jython"'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '19'], 'value': '+'}, {'id': '17', 'type': 'tuple', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getmro'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}
def _get_mro(cls): if platform.python_implementation() == "Jython": return (cls,) + cls.__bases__ return inspect.getmro(cls)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_walk'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '11', '17']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '17', 'type': 'block', 'children': ['18', '24', '30']}; {'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': 'dirs'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'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': 'files'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'yield', 'children': ['32']}; {'id': '32', 'type': 'expression_list', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dirs'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'files'}
def sorted_walk(dir): for base, dirs, files in os.walk(dir): dirs.sort() files.sort() yield base, dirs, files
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_all_ns_packages'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pkgs'}, {'id': '9', 'type': 'boolean_operator', 'children': ['10', '15'], 'value': 'or'}; {'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': 'distribution'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'namespace_packages'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_pkg_names'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pkgs'}
def _get_all_ns_packages(self): pkgs = self.distribution.namespace_packages or [] return sorted(flatten(map(self._pkg_names, pkgs)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatten_comments'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'comments'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'root_level'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '26', '34', '146']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '12', 'type': 'subscript', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'comments'}; {'id': '14', 'type': 'slice', 'children': ['15']}, {'id': '15', 'type': 'colon', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'nested_level'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'root_level'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'retval'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parent_candidates'}, {'id': '31', 'type': 'expression_list', 'children': ['32', '33']}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'while_statement', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '36', 'type': 'block', 'children': ['37', '46', '64', '97', '131', '139']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '62']}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '57'], 'value': 'and'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'praw'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'MoreComments'}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '61'], 'value': '=='}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'continue_statement', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'parent_id'}; {'id': '68', 'type': 'block', 'children': ['69', '84']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'parent_candidates'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'parent_id'}, {'id': '81', 'type': 'slice', 'children': ['82', '83']}; {'id': '82', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '83', 'type': 'colon', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nested_level'}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '96'], 'value': '+'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'nested_level'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '103']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'replies'"}, {'id': '103', 'type': 'block', 'children': ['104', '120']}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '109']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'replies'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'nested_level'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '119'], 'value': '+'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'nested_level'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '128']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '124', 'type': 'slice', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'colon', 'children': []}, {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'replies'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '138']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'parent_candidates'}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '146', 'type': 'return_statement', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'retval'}
def flatten_comments(comments, root_level=0): stack = comments[:] for item in stack: item.nested_level = root_level retval, parent_candidates = [], {} while stack: item = stack.pop(0) if isinstance(item, praw.objects.MoreComments) and item.count == 0: continue if item.parent_id: parent = parent_candidates.get(item.parent_id[3:]) if parent: item.nested_level = parent.nested_level + 1 if hasattr(item, 'replies'): for n in item.replies: n.nested_level = item.nested_level + 1 stack[0:0] = item.replies parent_candidates[item.id] = item retval.append(item) return retval
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_domain_listing'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'hot'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'list_splat_pattern', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'block', 'children': ['17', '33', '50', '64', '79', '88', '103']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '27']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'not'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '20', 'type': 'tuple', 'children': ['21', '22', '23', '24', '25', '26']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'controversial'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'hot'"}, {'id': '23', 'type': 'string', 'children': [], 'value': "'new'"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'rising'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'top'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'gilded'"}, {'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': 'TypeError'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'Invalid sort parameter.'"}, {'id': '33', 'type': 'if_statement', 'children': ['34', '44']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '36', 'type': 'tuple', 'children': ['37', '38', '39', '40', '41', '42', '43']}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'day'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'hour'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'month'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'week'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'year'"}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'Invalid period parameter.'"}; {'id': '50', 'type': 'if_statement', 'children': ['51', '58']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '57'], 'value': 'and'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'not'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '54', 'type': 'tuple', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "'controversial'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'top'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'raise_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'string', 'children': [], 'value': "'Period cannot be set for that sort argument.'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '67', 'type': 'call', 'children': ['68', '75']}; {'id': '68', 'type': 'attribute', 'children': ['69', '74']}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'domain'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'domain'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '!='}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'hot'"}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'augmented_assignment', 'children': ['86', '87'], 'value': '+='}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '102']}, {'id': '93', 'type': 'subscript', 'children': ['94', '101']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'params'"}; {'id': '100', 'type': 'dictionary', 'children': []}, {'id': '101', 'type': 'string', 'children': [], 'value': "'t'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'get_content'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110', '112']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '110', 'type': 'list_splat', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '112', 'type': 'dictionary_splat', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def get_domain_listing(self, domain, sort='hot', period=None, *args, **kwargs): if sort not in ('controversial', 'hot', 'new', 'rising', 'top', 'gilded'): raise TypeError('Invalid sort parameter.') if period not in (None, 'all', 'day', 'hour', 'month', 'week', 'year'): raise TypeError('Invalid period parameter.') if sort not in ('controversial', 'top') and period: raise TypeError('Period cannot be set for that sort argument.') url = self.config['domain'].format(domain=domain) if sort != 'hot': url += sort if period: kwargs.setdefault('params', {})['t'] = period return self.get_content(url, *args, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_submission'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'submission_id'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '37', '52']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '31']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '=='}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'submission_id'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'One (and only one) of id or url is required!'"}, {'id': '37', 'type': 'if_statement', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'submission_id'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'urljoin'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '51']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'comments'"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'submission_id'}; {'id': '52', 'type': 'return_statement', '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': 'objects'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Submission'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'from_url'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62', '65', '68']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'params'}
def get_submission(self, url=None, submission_id=None, comment_limit=0, comment_sort=None, params=None): if bool(url) == bool(submission_id): raise TypeError('One (and only one) of id or url is required!') if submission_id: url = urljoin(self.config['comments'], submission_id) return objects.Submission.from_url(self, url, comment_limit=comment_limit, comment_sort=comment_sort, params=params)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'subreddit'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'syntax'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'list_splat_pattern', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '30', '51', '60', '69', '78', '102', '117', '121']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '26', 'type': 'dictionary', 'children': ['27']}, {'id': '27', 'type': 'pair', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'q'"}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'block', 'children': ['35', '44']}, {'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': 'params'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'params'"}; {'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': 'kwargs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '51', 'type': 'if_statement', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'syntax'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'syntax'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'syntax'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'period'}, {'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': 'params'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'t'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80', '96']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'subreddit'}; {'id': '80', 'type': 'block', 'children': ['81', '87']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'restrict_sr'"}; {'id': '86', 'type': 'string', 'children': [], 'value': "'on'"}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'subreddit'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'subreddit'}; {'id': '96', 'type': 'else_clause', 'children': ['97']}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'subreddit'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '105', 'type': 'call', 'children': ['106', '113']}; {'id': '106', 'type': 'attribute', 'children': ['107', '112']}, {'id': '107', 'type': 'subscript', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'search'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'subreddit'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'subreddit'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '121', 'type': 'while_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '>'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'block', 'children': ['126', '130']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '-='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'depth'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'try_statement', 'children': ['131', '152']}, {'id': '131', 'type': 'block', 'children': ['132', '151']}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '147']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'get_content'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140', '143', '145']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '143', 'type': 'list_splat', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '145', 'type': 'dictionary_splat', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'yield', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '151', 'type': 'break_statement', 'children': []}; {'id': '152', 'type': 'except_clause', 'children': ['153', '159']}, {'id': '153', 'type': 'as_pattern', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'RedirectException'}, {'id': '157', 'type': 'as_pattern_target', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '159', 'type': 'block', 'children': ['160', '169', '197', '213']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'response_url'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '174', 'type': 'generator_expression', 'children': ['175', '183']}, {'id': '175', 'type': 'tuple', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'string', 'children': [], 'value': '","'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '183', 'type': 'for_in_clause', 'children': ['184', '187']}; {'id': '184', 'type': 'pattern_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '187', 'type': 'call', 'children': ['188', '196']}; {'id': '188', 'type': 'attribute', 'children': ['189', '195']}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'parse_qs'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '196', 'type': 'argument_list', 'children': []}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'urlunparse'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'binary_operator', 'children': ['204', '209'], 'value': '+'}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '206', 'type': 'slice', 'children': ['207', '208']}, {'id': '207', 'type': 'colon', 'children': []}; {'id': '208', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '209', 'type': 'tuple', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'string', 'children': [], 'value': '""'}, {'id': '211', 'type': 'string', 'children': [], 'value': '""'}; {'id': '212', 'type': 'string', 'children': [], 'value': '""'}, {'id': '213', 'type': 'if_statement', 'children': ['214', '217']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'in'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'already_submitted'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '217', 'type': 'block', 'children': ['218', '226']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'yield', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'get_submission'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'url'}
def search(self, query, subreddit=None, sort=None, syntax=None, period=None, *args, **kwargs): params = {'q': query} if 'params' in kwargs: params.update(kwargs['params']) kwargs.pop('params') if sort: params['sort'] = sort if syntax: params['syntax'] = syntax if period: params['t'] = period if subreddit: params['restrict_sr'] = 'on' subreddit = six.text_type(subreddit) else: subreddit = 'all' url = self.config['search'].format(subreddit=subreddit) depth = 2 while depth > 0: depth -= 1 try: for item in self.get_content(url, params=params, *args, **kwargs): yield item break except errors.RedirectException as exc: parsed = urlparse(exc.response_url) params = dict((k, ",".join(v)) for k, v in parse_qs(parsed.query).items()) url = urlunparse(parsed[:3] + ("", "", "")) if 'already_submitted' in params: yield self.get_submission(url) break
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'subpath'}; {'id': '6', 'type': 'string', 'children': [], 'value': "''"}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '9', 'type': 'block', 'children': ['10', '86']}; {'id': '10', 'type': 'decorated_definition', 'children': ['11', '18']}, {'id': '11', 'type': 'decorator', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'restrict_access'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'read'"}; {'id': '18', 'type': 'function_definition', 'children': ['19', '20', '26']}, {'id': '19', 'type': 'function_name', 'children': [], 'value': '_sorted'}; {'id': '20', 'type': 'parameters', 'children': ['21', '22', '24']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'list_splat_pattern', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '24', 'type': 'dictionary_splat_pattern', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'block', 'children': ['27', '42', '63', '73']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '35']}; {'id': '28', 'type': 'not_operator', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'for_statement', 'children': ['43', '46', '52']}, {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'params'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'urljoin'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'subpath'}, {'id': '73', 'type': 'return_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': 'reddit_session'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_content'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '84']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '82', 'type': 'list_splat', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '84', 'type': 'dictionary_splat', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_sorted'}
def _get_sorter(subpath='', **defaults): @restrict_access(scope='read') def _sorted(self, *args, **kwargs): if not kwargs.get('params'): kwargs['params'] = {} for key, value in six.iteritems(defaults): kwargs['params'].setdefault(key, value) url = urljoin(self._url, subpath) return self.reddit_session.get_content(url, *args, **kwargs) return _sorted
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_draw_banner'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '20', '38', '44', '62', '77', '90', '116', '129', '138', '150', '206']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_rows'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'n_cols'}, {'id': '11', 'type': 'call', 'children': ['12', '19']}; {'id': '12', 'type': 'attribute', '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': 'term'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stdscr'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'getmaxyx'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'window'}, {'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': 'term'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'stdscr'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'derwin'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '37']}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'n_cols'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_row'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'window'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'erase'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'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': 'window'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bkgd'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '54']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'term'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'OrderBar'"}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'banner'}, {'id': '65', 'type': 'conditional_expression', 'children': ['66', '69', '74'], 'value': 'if'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'docs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'BANNER_SEARCH'}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'BANNER'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '80', 'type': 'call', 'children': ['81', '88']}, {'id': '81', 'type': 'attribute', 'children': ['82', '87']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'banner'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'distance'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '109'], 'value': '/'}; {'id': '94', 'type': 'parenthesized_expression', 'children': ['95']}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '108'], 'value': '-'}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '-'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'n_cols'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '100', 'type': 'generator_expression', 'children': ['101', '105']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'parenthesized_expression', 'children': ['110']}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '115'], 'value': '-'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'spacing'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '128'], 'value': '*'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}, {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'distance'}; {'id': '128', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'spacing'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'add_line'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148', '149']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'window'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '158']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '157'], 'value': 'is'}; {'id': '152', 'type': 'attribute', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '157', 'type': 'None', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159', '174', '185', '196']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '162', 'type': 'subscript', 'children': ['163', '173']}, {'id': '163', 'type': 'call', 'children': ['164', '171']}; {'id': '164', 'type': 'attribute', 'children': ['165', '170']}, {'id': '165', 'type': 'attribute', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '173', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '184'], 'value': '-'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '188', 'type': 'call', 'children': ['189', '194']}, {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'term'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'string', 'children': [], 'value': "'OrderBarHighlight'"}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'window'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'chgat'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204', '205']}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '204', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'augmented_assignment', 'children': ['208', '211'], 'value': '+='}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_row'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '1'}
def _draw_banner(self): n_rows, n_cols = self.term.stdscr.getmaxyx() window = self.term.stdscr.derwin(1, n_cols, self._row, 0) window.erase() window.bkgd(str(' '), self.term.attr('OrderBar')) banner = docs.BANNER_SEARCH if self.content.query else self.BANNER items = banner.strip().split(' ') distance = (n_cols - sum(len(t) for t in items) - 1) / (len(items) - 1) spacing = max(1, int(distance)) * ' ' text = spacing.join(items) self.term.add_line(window, text, 0, 0) if self.content.order is not None: order = self.content.order.split('-')[0] col = text.find(order) - 3 attr = self.term.attr('OrderBarHighlight') window.chgat(0, col, 3, attr) self._row += 1
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_url'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reddit_session'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'comments_only'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '28', '35', '44', '67', '74', '90', '112', '121', '133', '144', '153', '159', '165']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '27', 'type': 'dictionary', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'query_pairs'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'parse_qs'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_params'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '49', 'type': 'generator_expression', 'children': ['50', '58']}; {'id': '50', 'type': 'tuple', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': '","'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '62']}, {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'query_pairs'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_params'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'urlunparse'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '86'], 'value': '+'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '83', 'type': 'slice', 'children': ['84', '85']}; {'id': '84', 'type': 'colon', 'children': []}, {'id': '85', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '86', 'type': 'tuple', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'string', 'children': [], 'value': '""'}; {'id': '88', 'type': 'string', 'children': [], 'value': '""'}, {'id': '89', 'type': 'string', 'children': [], 'value': '""'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94', '101']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '100', 'type': 'integer', 'children': [], 'value': '2048'}, {'id': '101', 'type': 'elif_clause', 'children': ['102', '105']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '>'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '111']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'limit'"}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'comment_limit'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'reddit_session'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'request_json'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'comments_only'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'return_statement', 'children': ['137']}, {'id': '137', 'type': 'subscript', 'children': ['138', '143']}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '143', 'type': 'string', 'children': [], 'value': "'children'"}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'submission'}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'Submission'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'from_json'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'submission'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_comment_sort'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'comment_sort'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'submission'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_params'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '165', 'type': 'return_statement', 'children': ['166']}
def from_url(reddit_session, url, comment_limit=0, comment_sort=None, comments_only=False, params=None): if params is None: params = {} parsed = urlparse(url) query_pairs = parse_qs(parsed.query) get_params = dict((k, ",".join(v)) for k, v in query_pairs.items()) params.update(get_params) url = urlunparse(parsed[:3] + ("", "", "")) if comment_limit is None: params['limit'] = 2048 elif comment_limit > 0: params['limit'] = comment_limit if comment_sort: params['sort'] = comment_sort response = reddit_session.request_json(url, params=params) if comments_only: return response[1]['data']['children'] submission = Submission.from_json(response) submission._comment_sort = comment_sort submission._params = params return submission
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_suggested_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'blank'"}; {'id': '8', 'type': 'block', 'children': ['9', '19', '31']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '12', 'type': 'subscript', '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': 'reddit_session'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'suggested_sort'"}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '22', 'type': 'dictionary', 'children': ['23', '28']}, {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fullname'}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', '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': 'reddit_session'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'request_json'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'data'}
def set_suggested_sort(self, sort='blank'): url = self.reddit_session.config['suggested_sort'] data = {'id': self.fullname, 'sort': sort} return self.reddit_session.request_json(url, data=data)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_jump_back'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'extended_arg'}, {'id': '7', 'type': 'block', 'children': ['8', '23']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '20']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': '!='}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'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': 'opc'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'JUMP_ABSOLUTE'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '>'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_target'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'offset'}
def is_jump_back(self, offset, extended_arg): if self.code[offset] != self.opc.JUMP_ABSOLUTE: return False return offset > self.get_target(offset, extended_arg)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_jump_forward'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '25', '32']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'opname'}; {'id': '10', 'type': 'attribute', 'children': ['11', '17']}, {'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_inst'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'opname'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'opname'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'JUMP_FORWARD'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'True', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '!='}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'opname'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'JUMP_ABSOLUTE'"}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '<'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_target'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}
def is_jump_forward(self, offset): opname = self.get_inst(offset).opname if opname == 'JUMP_FORWARD': return True if opname != 'JUMP_ABSOLUTE': return False return offset < self.get_target(offset)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'show_grid'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_frame'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'show_toolbar'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'column_options'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'column_definitions'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'row_edit_callback'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '35', '46', '64', '98', '132', '150', '188', '195']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'show_toolbar'}, {'id': '27', 'type': 'None', 'children': []}; {'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': 'show_toolbar'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'show_toolbar'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '53']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'Integral'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'raise_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'}, {'id': '59', 'type': 'string', 'children': [], 'value': '"precision must be int, not %s"'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68', '75']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'column_options'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'column_options'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'column_options'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77', '87', '94']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'column_options'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'column_options'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'column_options'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102', '109']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'grid_options'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111', '121', '128']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '114', 'type': 'call', 'children': ['115', '120']}, {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'grid_options'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '139']}, {'id': '133', 'type': 'not_operator', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'grid_options'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'raise_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '%'}, {'id': '145', 'type': 'string', 'children': [], 'value': '"grid_options must be dict, not %s"'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'grid_options'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '158', '168']}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'data_frame'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'Series'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'data_frame'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pd'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'data_frame'}; {'id': '168', 'type': 'elif_clause', 'children': ['169', '177']}, {'id': '169', 'type': 'not_operator', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'data_frame'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'raise_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '%'}, {'id': '183', 'type': 'string', 'children': [], 'value': '"data_frame must be DataFrame or Series, not %s"'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'data_frame'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'column_definitions'}, {'id': '191', 'type': 'parenthesized_expression', 'children': ['192']}; {'id': '192', 'type': 'boolean_operator', 'children': ['193', '194'], 'value': 'or'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'column_definitions'}; {'id': '194', 'type': 'dictionary', 'children': []}, {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'QgridWidget'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '202', '205', '208', '211', '214', '217']}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'data_frame'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'grid_options'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'grid_options'}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'column_options'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'column_options'}, {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'column_definitions'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'column_definitions'}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'row_edit_callback'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'row_edit_callback'}, {'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'show_toolbar'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'show_toolbar'}
def show_grid(data_frame, show_toolbar=None, precision=None, grid_options=None, column_options=None, column_definitions=None, row_edit_callback=None): if show_toolbar is None: show_toolbar = defaults.show_toolbar if precision is None: precision = defaults.precision if not isinstance(precision, Integral): raise TypeError("precision must be int, not %s" % type(precision)) if column_options is None: column_options = defaults.column_options else: options = defaults.column_options.copy() options.update(column_options) column_options = options if grid_options is None: grid_options = defaults.grid_options else: options = defaults.grid_options.copy() options.update(grid_options) grid_options = options if not isinstance(grid_options, dict): raise TypeError( "grid_options must be dict, not %s" % type(grid_options) ) if isinstance(data_frame, pd.Series): data_frame = pd.DataFrame(data_frame) elif not isinstance(data_frame, pd.DataFrame): raise TypeError( "data_frame must be DataFrame or Series, not %s" % type(data_frame) ) column_definitions = (column_definitions or {}) return QgridWidget(df=data_frame, precision=precision, grid_options=grid_options, column_options=column_options, column_definitions=column_definitions, row_edit_callback=row_edit_callback, show_toolbar=show_toolbar)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_eigsorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cov'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '22', '30', '44']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'eigval'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'eigvec'}; {'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': 'np'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'eigh'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cov'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'eigval'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '33']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '39', 'type': 'slice', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'colon', 'children': []}, {'id': '41', 'type': 'colon', 'children': []}; {'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'expression_list', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'eigval'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51', '53']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'eigvec'}, {'id': '51', 'type': 'slice', 'children': ['52']}; {'id': '52', 'type': 'colon', 'children': []}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'}
def _eigsorted(cov, asc=True): eigval, eigvec = np.linalg.eigh(cov) order = eigval.argsort() if not asc: order = order[::-1] return eigval[order], eigvec[:, order]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_args'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '31', '42']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'flags'}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '22', 'type': 'if_clause', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'FLAGS_RE'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'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': 'args'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'flags'}
def sort_args(args): args = args.copy() flags = [i for i in args if FLAGS_RE.match(i[1])] for i in flags: args.remove(i) return args + flags
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_fracs'}, {'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': 'Q'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'fignum'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '22', '28', '36', '59', '70', '79', '100', '122', '129', '136', '150', '170', '181']}, {'id': '15', 'type': 'import_from_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'relative_import', 'children': ['17', '18']}, {'id': '17', 'type': 'import_prefix', 'children': []}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'plotting'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Tango'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Tango'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reset'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Tango'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'nextMedium'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '50']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pylab'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'figure'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fignum'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'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': 'fig'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'add_subplot'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'integer', 'children': [], 'value': '111'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'Q'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'Q'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bar'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90', '97']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '-'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '89', 'type': 'float', 'children': [], 'value': '.4'}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fracs'}; {'id': '94', 'type': 'slice', 'children': ['95', '96']}, {'id': '95', 'type': 'colon', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Q'}, {'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'col'}; {'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': 'ax'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'set_xticks'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '119']}; {'id': '110', 'type': 'lambda', 'children': ['111', '113']}, {'id': '111', 'type': 'lambda_parameters', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': 'r"${}$"'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'ax'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'string', 'children': [], 'value': '"Eigenvalue fraction"'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"PC"'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'set_ylim'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'subscript', 'children': ['144', '149']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ax'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_ylim'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'set_xlim'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '163']}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '162'], 'value': '-'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ticks'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'float', 'children': [], 'value': '.5'}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '169'], 'value': '+'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'float', 'children': [], 'value': '.5'}; {'id': '170', 'type': 'try_statement', 'children': ['171', '178']}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'pylab'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'tight_layout'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'except_clause', 'children': ['179']}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'pass_statement', 'children': []}, {'id': '181', 'type': 'return_statement', 'children': ['182']}
def plot_fracs(self, Q=None, ax=None, fignum=None): from ..plotting import Tango Tango.reset() col = Tango.nextMedium() if ax is None: fig = pylab.figure(fignum) ax = fig.add_subplot(111) if Q is None: Q = self.Q ticks = numpy.arange(Q) bar = ax.bar(ticks - .4, self.fracs[:Q], color=col) ax.set_xticks(ticks, map(lambda x: r"${}$".format(x), ticks + 1)) ax.set_ylabel("Eigenvalue fraction") ax.set_xlabel("PC") ax.set_ylim(0, ax.get_ylim()[1]) ax.set_xlim(ticks.min() - .5, ticks.max() + .5) try: pylab.tight_layout() except: pass return bar
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_distance_squared'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Point2"'}, {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'generic_type', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Union'}; {'id': '12', 'type': 'type_parameter', 'children': ['13', '15']}, {'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': 'float'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '30'], 'value': '+'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '29'], 'value': '**'}, {'id': '21', 'type': 'parenthesized_expression', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '26'], 'value': '-'}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '39'], 'value': '**'}, {'id': '31', 'type': 'parenthesized_expression', 'children': ['32']}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '36'], 'value': '-'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '2'}
def _distance_squared(self, p2: "Point2") -> Union[int, float]: return (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_of_type'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'with_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'with_clause', 'children': ['9']}, {'id': '9', 'type': 'with_item', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_condition'}, {'id': '13', 'type': 'block', 'children': ['14', '26', '50', '56']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'processor_type'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'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': 'wait_for_registration'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '26', 'type': 'try_statement', 'children': ['27', '38']}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'processor'}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'next_processor'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'except_clause', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'NoProcessorVacancyError'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'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': 'wait_for_vacancy'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inc_occupancy'}, {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'processor'}
def get_next_of_type(self, processor_type): with self._condition: if processor_type not in self: self.wait_for_registration(processor_type) try: processor = self[processor_type].next_processor() except NoProcessorVacancyError: processor = self.wait_for_vacancy(processor_type) processor.inc_occupancy() return processor
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_for_registration'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'with_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'with_clause', 'children': ['9']}, {'id': '9', 'type': 'with_item', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_condition'}, {'id': '13', 'type': 'block', 'children': ['14', '35']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_condition'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'wait_for'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'lambda', 'children': ['23']}, {'id': '23', 'type': 'parenthesized_expression', 'children': ['24']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '28'], 'value': 'or'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'processor_type'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': '_cancelled_event'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'is_set'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '43']}; {'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': '_cancelled_event'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'is_set'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'WaitCancelledException'}, {'id': '47', 'type': 'argument_list', 'children': []}
def wait_for_registration(self, processor_type): with self._condition: self._condition.wait_for(lambda: ( processor_type in self or self._cancelled_event.is_set())) if self._cancelled_event.is_set(): raise WaitCancelledException()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_for_vacancy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'processor_type'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'with_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'with_clause', 'children': ['9']}, {'id': '9', 'type': 'with_item', 'children': ['10']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_condition'}, {'id': '13', 'type': 'block', 'children': ['14', '38', '51', '61']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_condition'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'wait_for'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'lambda', 'children': ['23']}, {'id': '23', 'type': 'parenthesized_expression', 'children': ['24']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '31'], 'value': 'or'}, {'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': '_processor_available'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'processor_type'}, {'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': '_cancelled_event'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'is_set'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'if_statement', 'children': ['39', '46']}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_cancelled_event'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'is_set'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'raise_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'WaitCancelledException'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'processor_type'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'next_processor'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'return_statement', 'children': ['62']}
def wait_for_vacancy(self, processor_type): with self._condition: self._condition.wait_for(lambda: ( self._processor_available(processor_type) or self._cancelled_event.is_set())) if self._cancelled_event.is_set(): raise WaitCancelledException() processor = self[processor_type].next_processor() return processor
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorting_message'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '25', '32', '94']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'control_list'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '14', 'type': 'call', 'children': ['15', '22']}, {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'reverse'"}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'control_list'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '40', '63']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '39'], 'value': '=='}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'string', 'children': [], 'value': '""'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'control_list'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'client_list_control_pb2'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ClientSortControls'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '55']}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '54', 'type': 'True', 'children': []}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '","'}, {'id': '63', 'type': 'elif_clause', 'children': ['64', '71']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '70'], 'value': '!='}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'string', 'children': [], 'value': "'false'"}, {'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': 'control_list'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'client_list_control_pb2'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ClientSortControls'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '86']}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '85', 'type': 'True', 'children': []}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'string', 'children': [], 'value': '","'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'control_list'}
def _get_sorting_message(request, key): control_list = [] reverse = request.url.query.get('reverse', None) if reverse is None: return control_list if reverse.lower() == "": control_list.append(client_list_control_pb2.ClientSortControls( reverse=True, keys=key.split(",") )) elif reverse.lower() != 'false': control_list.append(client_list_control_pb2.ClientSortControls( reverse=True, keys=reverse.split(",") )) return control_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_resources'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'resources'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fail_enum'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'header_proto'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '20', '31', '80']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '17']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'resources'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'value_handlers'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_get_handler_set'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fail_enum'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'header_proto'}, {'id': '31', 'type': 'function_definition', 'children': ['32', '33', '36']}; {'id': '32', 'type': 'function_name', 'children': [], 'value': 'sorter'}, {'id': '33', 'type': 'parameters', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'resource_a'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'resource_b'}; {'id': '36', 'type': 'block', 'children': ['37', '78']}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value_handlers'}; {'id': '40', 'type': 'block', 'children': ['41', '53', '66']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}, {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'val_a'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'val_b'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_sort_values'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'resource_a'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'resource_b'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '<'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'val_a'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'val_b'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'xform_result'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '-'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '>'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'val_a'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'val_b'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'xform_result'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'resources'}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}
def sort_resources(cls, request, resources, fail_enum, header_proto=None): if not request.sorting: return resources value_handlers = cls._get_handler_set(request, fail_enum, header_proto) def sorter(resource_a, resource_b): for handler in value_handlers: val_a, val_b = handler.get_sort_values(resource_a, resource_b) if val_a < val_b: return handler.xform_result(-1) if val_a > val_b: return handler.xform_result(1) return 0 return sorted(resources, key=cmp_to_key(sorter))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_handler_set'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fail_enum'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'header_proto'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '17', '21', '61']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '26']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'controls'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '26', 'type': 'block', 'children': ['27', '35']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'control_bytes'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'controls'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'SerializeToString'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'not'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'control_bytes'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'added'}, {'id': '39', 'type': 'block', 'children': ['40', '47']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'control_bytes'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'handlers'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_ValueHandler'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'controls'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fail_enum'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'header_proto'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}
def _get_handler_set(cls, request, fail_enum, header_proto=None): added = set() handlers = [] for controls in request.sorting: control_bytes = controls.SerializeToString() if control_bytes not in added: added.add(control_bytes) handlers.append( cls._ValueHandler(controls, fail_enum, header_proto)) return handlers
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_write_predecessors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '17', '28', '35', '117', '153']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'predecessors'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'}; {'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': 'enclosing_writer'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'node_stream'}; {'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': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_tree'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'address_len'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '35', 'type': 'try_statement', 'children': ['36', '79', '103']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'for_statement', 'children': ['38', '41', '42']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'node_address'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'node_stream'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '47']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48', '57', '70']}; {'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': 'predecessors'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'readers'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '63']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': 'is'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'writer'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'enclosing_writer'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'writer'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '77']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '>='}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'node_address'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'address_len'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'break_statement', 'children': []}, {'id': '79', 'type': 'except_clause', 'children': ['80', '84']}; {'id': '80', 'type': 'as_pattern', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'AddressNotInTree'}; {'id': '82', 'type': 'as_pattern_target', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '84', 'type': 'block', 'children': ['85', '101']}, {'id': '85', 'type': 'if_statement', 'children': ['86', '91']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': 'is'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'return_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'find_write_predecessors'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'predecessors'}, {'id': '103', 'type': 'finally_clause', 'children': ['104']}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'enclosing_writer'}; {'id': '108', 'type': 'None', 'children': []}, {'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': 'predecessors'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'enclosing_writer'}, {'id': '117', 'type': 'for_statement', 'children': ['118', '121', '122']}; {'id': '118', 'type': 'pattern_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'node_stream'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'if_statement', 'children': ['124', '127']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '126', 'type': 'None', 'children': []}, {'id': '127', 'type': 'block', 'children': ['128', '144']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '134']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'is'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'writer'}, {'id': '133', 'type': 'None', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'predecessors'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'writer'}; {'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': 'predecessors'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'readers'}, {'id': '153', 'type': 'return_statement', 'children': ['154']}
def find_write_predecessors(self, address): predecessors = set() enclosing_writer = None node_stream = self._tree.walk(address) address_len = len(address) try: for node_address, node in node_stream: if node is not None: predecessors.update(node.readers) if node.writer is not None: enclosing_writer = node.writer if len(node_address) >= address_len: break except AddressNotInTree as err: if err.match is not None: return self.find_write_predecessors(err.match) return predecessors finally: if enclosing_writer is not None: predecessors.add(enclosing_writer) for _, node in node_stream: if node is not None: if node.writer is not None: predecessors.add(node.writer) predecessors.update(node.readers) return predecessors
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_efron_values_single'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '10', 'type': 'block', 'children': ['11', '19', '30', '40', '44', '54', '62', '82', '104', '108', '112', '129', '473']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '16']}, {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'tuple', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'gradient'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'tuple', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'log_lik'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'tuple', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'pattern_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}, {'id': '59', 'type': 'expression_list', 'children': ['60', '61']}; {'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', '67']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}, {'id': '67', 'type': 'expression_list', 'children': ['68', '75']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'tuple', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'tuple', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '87', 'type': 'expression_list', 'children': ['88', '96']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'tuple', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'tuple', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'weight_count'}, {'id': '107', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'scores'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '*'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'beta'}, {'id': '129', 'type': 'for_statement', 'children': ['130', '131', '141']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '137', '139']}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '-'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'block', 'children': ['142', '148', '154', '160', '166', '172', '176', '182', '192', '198', '204', '210', '247', '267', '273', '358', '368', '379', '394', '419', '430', '434', '438', '448', '452', '462']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ti'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ei'}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'xi'}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'scores'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'phi_i'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '*'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'phi_i'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'xi'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'phi_x_x_i'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'outer'}, {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'xi'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}, {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'phi_i'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '+'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '+'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'phi_x_x_i'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'ei'}; {'id': '212', 'type': 'block', 'children': ['213', '221', '227', '233', '239', '243']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '+'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '*'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'xi'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '+'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'phi_i'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '+'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'phi_x_x_i'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'augmented_assignment', 'children': ['241', '242'], 'value': '+='}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'weight_count'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '259', '261']}; {'id': '248', 'type': 'boolean_operator', 'children': ['249', '252'], 'value': 'and'}, {'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '>'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '258'], 'value': '=='}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '255', 'type': 'binary_operator', 'children': ['256', '257'], 'value': '-'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ti'}, {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'continue_statement', 'children': []}, {'id': '261', 'type': 'elif_clause', 'children': ['262', '265']}; {'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '=='}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'continue_statement', 'children': []}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '/'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'weight_count'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '273', 'type': 'if_statement', 'children': ['274', '277', '334']}; {'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': '>'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '276', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '277', 'type': 'block', 'children': ['278', '289', '300', '312']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '281', 'type': 'binary_operator', 'children': ['282', '288'], 'value': '/'}; {'id': '282', 'type': 'call', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '292', 'type': 'binary_operator', 'children': ['293', '294'], 'value': '/'}, {'id': '293', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '294', 'type': 'parenthesized_expression', 'children': ['295']}, {'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '-'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '*'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '-'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'outer'}, {'id': '309', 'type': 'argument_list', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '315', 'type': 'binary_operator', 'children': ['316', '324'], 'value': '-'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'einsum'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322', '323']}, {'id': '321', 'type': 'string', 'children': [], 'value': '"ab,i->ab"'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'einsum'}; {'id': '328', 'type': 'argument_list', 'children': ['329', '330', '331']}, {'id': '329', 'type': 'string', 'children': [], 'value': '"ab,i->ab"'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '331', 'type': 'binary_operator', 'children': ['332', '333'], 'value': '*'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '334', 'type': 'else_clause', 'children': ['335']}, {'id': '335', 'type': 'block', 'children': ['336', '348', '352']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '339', 'type': 'binary_operator', 'children': ['340', '341'], 'value': '/'}; {'id': '340', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '341', 'type': 'call', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '345', 'type': 'argument_list', 'children': ['346']}; {'id': '346', 'type': 'list', 'children': ['347'], 'value': '[risk_phi]'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '348', 'type': 'expression_statement', 'children': ['349']}, {'id': '349', 'type': 'assignment', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '355', 'type': 'binary_operator', 'children': ['356', '357'], 'value': '*'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'assignment', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '361', 'type': 'binary_operator', 'children': ['362', '363'], 'value': '*'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '363', 'type': 'subscript', 'children': ['364', '365', '367']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '365', 'type': 'slice', 'children': ['366']}; {'id': '366', 'type': 'colon', 'children': []}, {'id': '367', 'type': 'None', 'children': []}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '371', 'type': 'call', 'children': ['372', '377']}; {'id': '372', 'type': 'attribute', 'children': ['373', '376']}, {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'assignment', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'gradient'}; {'id': '382', 'type': 'binary_operator', 'children': ['383', '386'], 'value': '-'}, {'id': '383', 'type': 'binary_operator', 'children': ['384', '385'], 'value': '+'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'gradient'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '*'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '388', 'type': 'call', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '392', 'type': 'argument_list', 'children': ['393']}, {'id': '393', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '394', 'type': 'expression_statement', 'children': ['395']}, {'id': '395', 'type': 'assignment', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'log_lik'}, {'id': '397', 'type': 'binary_operator', 'children': ['398', '407'], 'value': '+'}; {'id': '398', 'type': 'binary_operator', 'children': ['399', '400'], 'value': '+'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'log_lik'}; {'id': '400', 'type': 'call', 'children': ['401', '404']}, {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '404', 'type': 'argument_list', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'beta'}, {'id': '407', 'type': 'binary_operator', 'children': ['408', '409'], 'value': '*'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}, {'id': '409', 'type': 'call', 'children': ['410', '418']}; {'id': '410', 'type': 'attribute', 'children': ['411', '417']}, {'id': '411', 'type': 'call', 'children': ['412', '415']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '415', 'type': 'argument_list', 'children': ['416']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '418', 'type': 'argument_list', 'children': []}, {'id': '419', 'type': 'expression_statement', 'children': ['420']}; {'id': '420', 'type': 'assignment', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '422', 'type': 'binary_operator', 'children': ['423', '424'], 'value': '+'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '424', 'type': 'binary_operator', 'children': ['425', '426'], 'value': '*'}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '426', 'type': 'parenthesized_expression', 'children': ['427']}, {'id': '427', 'type': 'binary_operator', 'children': ['428', '429'], 'value': '-'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'a1'}; {'id': '430', 'type': 'expression_statement', 'children': ['431']}, {'id': '431', 'type': 'assignment', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '433', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '434', 'type': 'expression_statement', 'children': ['435']}, {'id': '435', 'type': 'assignment', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'weight_count'}, {'id': '437', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '438', 'type': 'expression_statement', 'children': ['439']}, {'id': '439', 'type': 'assignment', 'children': ['440', '441']}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}, {'id': '441', 'type': 'call', 'children': ['442', '445']}; {'id': '442', 'type': 'attribute', 'children': ['443', '444']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '445', 'type': 'argument_list', 'children': ['446']}; {'id': '446', 'type': 'tuple', 'children': ['447']}, {'id': '447', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '448', 'type': 'expression_statement', 'children': ['449']}, {'id': '449', 'type': 'assignment', 'children': ['450', '451']}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}, {'id': '451', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '452', 'type': 'expression_statement', 'children': ['453']}, {'id': '453', 'type': 'assignment', 'children': ['454', '455']}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}, {'id': '455', 'type': 'call', 'children': ['456', '459']}; {'id': '456', 'type': 'attribute', 'children': ['457', '458']}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '458', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '459', 'type': 'argument_list', 'children': ['460']}; {'id': '460', 'type': 'tuple', 'children': ['461']}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '462', 'type': 'expression_statement', 'children': ['463']}, {'id': '463', 'type': 'assignment', 'children': ['464', '465']}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '465', 'type': 'call', 'children': ['466', '469']}; {'id': '466', 'type': 'attribute', 'children': ['467', '468']}, {'id': '467', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '468', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '469', 'type': 'argument_list', 'children': ['470']}; {'id': '470', 'type': 'tuple', 'children': ['471', '472']}, {'id': '471', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '472', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '473', 'type': 'return_statement', 'children': ['474']}; {'id': '474', 'type': 'expression_list', 'children': ['475', '476', '477']}, {'id': '475', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '476', 'type': 'identifier', 'children': [], 'value': 'gradient'}, {'id': '477', 'type': 'identifier', 'children': [], 'value': 'log_lik'}
def _get_efron_values_single(self, X, T, E, weights, beta): n, d = X.shape hessian = np.zeros((d, d)) gradient = np.zeros((d,)) log_lik = 0 x_death_sum = np.zeros((d,)) risk_phi, tie_phi = 0, 0 risk_phi_x, tie_phi_x = np.zeros((d,)), np.zeros((d,)) risk_phi_x_x, tie_phi_x_x = np.zeros((d, d)), np.zeros((d, d)) weight_count = 0.0 tied_death_counts = 0 scores = weights * np.exp(np.dot(X, beta)) for i in range(n - 1, -1, -1): ti = T[i] ei = E[i] xi = X[i] score = scores[i] w = weights[i] phi_i = score phi_x_i = phi_i * xi phi_x_x_i = np.outer(xi, phi_x_i) risk_phi = risk_phi + phi_i risk_phi_x = risk_phi_x + phi_x_i risk_phi_x_x = risk_phi_x_x + phi_x_x_i if ei: x_death_sum = x_death_sum + w * xi tie_phi = tie_phi + phi_i tie_phi_x = tie_phi_x + phi_x_i tie_phi_x_x = tie_phi_x_x + phi_x_x_i tied_death_counts += 1 weight_count += w if i > 0 and T[i - 1] == ti: continue elif tied_death_counts == 0: continue weighted_average = weight_count / tied_death_counts if tied_death_counts > 1: increasing_proportion = np.arange(tied_death_counts) / tied_death_counts denom = 1.0 / (risk_phi - increasing_proportion * tie_phi) numer = risk_phi_x - np.outer(increasing_proportion, tie_phi_x) a1 = np.einsum("ab,i->ab", risk_phi_x_x, denom) - np.einsum( "ab,i->ab", tie_phi_x_x, increasing_proportion * denom ) else: denom = 1.0 / np.array([risk_phi]) numer = risk_phi_x a1 = risk_phi_x_x * denom summand = numer * denom[:, None] a2 = summand.T.dot(summand) gradient = gradient + x_death_sum - weighted_average * summand.sum(0) log_lik = log_lik + np.dot(x_death_sum, beta) + weighted_average * np.log(denom).sum() hessian = hessian + weighted_average * (a2 - a1) tied_death_counts = 0 weight_count = 0.0 x_death_sum = np.zeros((d,)) tie_phi = 0 tie_phi_x = np.zeros((d,)) tie_phi_x_x = np.zeros((d, d)) return hessian, gradient, log_lik
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_efron_values_batch'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '10', 'type': 'block', 'children': ['11', '19', '30', '40', '44', '52', '72', '94', '109', '126', '130', '466']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '16']}, {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'tuple', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'gradient'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'tuple', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'log_lik'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}, {'id': '49', 'type': 'expression_list', 'children': ['50', '51']}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}, {'id': '57', 'type': 'expression_list', 'children': ['58', '65']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'tuple', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'}, {'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': 'zeros'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'tuple', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '77', 'type': 'expression_list', 'children': ['78', '86']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'tuple', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'tuple', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'pattern_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '106']}; {'id': '104', 'type': 'unary_operator', 'children': ['105'], 'value': '-'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'return_counts'}; {'id': '108', 'type': 'True', 'children': []}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '*'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'count_of_removals'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'counts'}, {'id': '133', 'type': 'block', 'children': ['134', '144', '150', '156', '163', '169', '181', '190', '199', '205', '211', '223', '233', '239', '245', '258', '265', '271', '390', '400', '411', '426', '451', '462']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'slice_'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'slice'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '143']}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '-'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'count_of_removals'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'X_at_t'}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'X'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'slice_'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'weights_at_t'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'slice_'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'phi_i'}, {'id': '159', 'type': 'subscript', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'scores'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'slice_'}; {'id': '162', 'type': 'None', 'children': []}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '*'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'phi_i'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'X_at_t'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'phi_x_x_i'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'X_at_t'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '+'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '186', 'type': 'call', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'array_sum_to_scalar'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'phi_i'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'matrix_axis_0_sum_to_array'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '+'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'phi_x_x_i'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'deaths'}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'slice_'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'array_sum_to_scalar'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'deaths'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'astype'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '223', 'type': 'if_statement', 'children': ['224', '227']}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '=='}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '226', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '227', 'type': 'block', 'children': ['228', '232']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'augmented_assignment', 'children': ['230', '231'], 'value': '-='}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'count_of_removals'}; {'id': '232', 'type': 'continue_statement', 'children': []}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'xi_deaths'}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'X_at_t'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'deaths'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'weights_deaths'}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'weights_at_t'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'deaths'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'matrix_axis_0_sum_to_array'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'binary_operator', 'children': ['252', '257'], 'value': '*'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254', '256']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'weights_deaths'}; {'id': '254', 'type': 'slice', 'children': ['255']}, {'id': '255', 'type': 'colon', 'children': []}; {'id': '256', 'type': 'None', 'children': []}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'xi_deaths'}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'weight_count'}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'array_sum_to_scalar'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'weights_deaths'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '/'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'weight_count'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '271', 'type': 'if_statement', 'children': ['272', '275', '366']}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': '>'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '275', 'type': 'block', 'children': ['276', '285', '294', '310', '321', '332', '344']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'array_sum_to_scalar'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'phi_i'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'deaths'}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}; {'id': '288', 'type': 'call', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'matrix_axis_0_sum_to_array'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}, {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'phi_x_i'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'deaths'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '301', 'type': 'argument_list', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'xi_deaths'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '305', 'type': 'binary_operator', 'children': ['306', '309'], 'value': '*'}; {'id': '306', 'type': 'subscript', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'phi_i'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'deaths'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'xi_deaths'}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '313', 'type': 'binary_operator', 'children': ['314', '320'], 'value': '/'}; {'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': 'identifier', 'children': [], 'value': 'tied_death_counts'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'tied_death_counts'}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '324', 'type': 'binary_operator', 'children': ['325', '326'], 'value': '/'}, {'id': '325', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '326', 'type': 'parenthesized_expression', 'children': ['327']}, {'id': '327', 'type': 'binary_operator', 'children': ['328', '329'], 'value': '-'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}, {'id': '329', 'type': 'binary_operator', 'children': ['330', '331'], 'value': '*'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'tie_phi'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'assignment', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '335', 'type': 'binary_operator', 'children': ['336', '337'], 'value': '-'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'outer'}, {'id': '341', 'type': 'argument_list', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x'}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}, {'id': '345', 'type': 'assignment', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '347', 'type': 'binary_operator', 'children': ['348', '356'], 'value': '-'}; {'id': '348', 'type': 'call', 'children': ['349', '352']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'einsum'}; {'id': '352', 'type': 'argument_list', 'children': ['353', '354', '355']}, {'id': '353', 'type': 'string', 'children': [], 'value': '"ab,i->ab"'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '356', 'type': 'call', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'einsum'}; {'id': '360', 'type': 'argument_list', 'children': ['361', '362', '363']}, {'id': '361', 'type': 'string', 'children': [], 'value': '"ab,i->ab"'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'tie_phi_x_x'}, {'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '*'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'increasing_proportion'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '366', 'type': 'else_clause', 'children': ['367']}, {'id': '367', 'type': 'block', 'children': ['368', '380', '384']}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '371', 'type': 'binary_operator', 'children': ['372', '373'], 'value': '/'}; {'id': '372', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'list', 'children': ['379'], 'value': '[risk_phi]'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'risk_phi'}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}, {'id': '381', 'type': 'assignment', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x'}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}, {'id': '385', 'type': 'assignment', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'a1'}, {'id': '387', 'type': 'binary_operator', 'children': ['388', '389'], 'value': '*'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'risk_phi_x_x'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'denom'}; {'id': '390', 'type': 'expression_statement', 'children': ['391']}, {'id': '391', 'type': 'assignment', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '393', 'type': 'binary_operator', 'children': ['394', '395'], 'value': '*'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'numer'}, {'id': '395', 'type': 'subscript', 'children': ['396', '397', '399']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '397', 'type': 'slice', 'children': ['398']}; {'id': '398', 'type': 'colon', 'children': []}, {'id': '399', 'type': 'None', 'children': []}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}, {'id': '401', 'type': 'assignment', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '403', 'type': 'call', 'children': ['404', '409']}; {'id': '404', 'type': 'attribute', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '409', 'type': 'argument_list', 'children': ['410']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '411', 'type': 'expression_statement', 'children': ['412']}; {'id': '412', 'type': 'assignment', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'gradient'}; {'id': '414', 'type': 'binary_operator', 'children': ['415', '418'], 'value': '-'}, {'id': '415', 'type': 'binary_operator', 'children': ['416', '417'], 'value': '+'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'gradient'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '418', 'type': 'binary_operator', 'children': ['419', '420'], 'value': '*'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '420', 'type': 'call', 'children': ['421', '424']}, {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'summand'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '424', 'type': 'argument_list', 'children': ['425']}, {'id': '425', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '426', 'type': 'expression_statement', 'children': ['427']}, {'id': '427', 'type': 'assignment', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'log_lik'}, {'id': '429', 'type': 'binary_operator', 'children': ['430', '439'], 'value': '+'}; {'id': '430', 'type': 'binary_operator', 'children': ['431', '432'], 'value': '+'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'log_lik'}; {'id': '432', 'type': 'call', 'children': ['433', '436']}, {'id': '433', 'type': 'attribute', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '436', 'type': 'argument_list', 'children': ['437', '438']}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'x_death_sum'}; {'id': '438', 'type': 'identifier', 'children': [], 'value': 'beta'}, {'id': '439', 'type': 'binary_operator', 'children': ['440', '441'], 'value': '*'}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}, {'id': '441', 'type': 'call', 'children': ['442', '450']}; {'id': '442', 'type': 'attribute', 'children': ['443', '449']}, {'id': '443', 'type': 'call', 'children': ['444', '447']}; {'id': '444', 'type': 'attribute', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '447', 'type': 'argument_list', 'children': ['448']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'denom'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '450', 'type': 'argument_list', 'children': []}, {'id': '451', 'type': 'expression_statement', 'children': ['452']}; {'id': '452', 'type': 'assignment', 'children': ['453', '454']}, {'id': '453', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '454', 'type': 'binary_operator', 'children': ['455', '456'], 'value': '+'}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'hessian'}; {'id': '456', 'type': 'binary_operator', 'children': ['457', '458'], 'value': '*'}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'weighted_average'}; {'id': '458', 'type': 'parenthesized_expression', 'children': ['459']}, {'id': '459', 'type': 'binary_operator', 'children': ['460', '461'], 'value': '-'}; {'id': '460', 'type': 'identifier', 'children': [], 'value': 'a2'}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'a1'}; {'id': '462', 'type': 'expression_statement', 'children': ['463']}, {'id': '463', 'type': 'augmented_assignment', 'children': ['464', '465'], 'value': '-='}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '465', 'type': 'identifier', 'children': [], 'value': 'count_of_removals'}; {'id': '466', 'type': 'return_statement', 'children': ['467']}, {'id': '467', 'type': 'expression_list', 'children': ['468', '469', '470']}; {'id': '468', 'type': 'identifier', 'children': [], 'value': 'hessian'}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'gradient'}
def _get_efron_values_batch(self, X, T, E, weights, beta): n, d = X.shape hessian = np.zeros((d, d)) gradient = np.zeros((d,)) log_lik = 0 risk_phi, tie_phi = 0, 0 risk_phi_x, tie_phi_x = np.zeros((d,)), np.zeros((d,)) risk_phi_x_x, tie_phi_x_x = np.zeros((d, d)), np.zeros((d, d)) _, counts = np.unique(-T, return_counts=True) scores = weights * np.exp(np.dot(X, beta)) pos = n for count_of_removals in counts: slice_ = slice(pos - count_of_removals, pos) X_at_t = X[slice_] weights_at_t = weights[slice_] phi_i = scores[slice_, None] phi_x_i = phi_i * X_at_t phi_x_x_i = np.dot(X_at_t.T, phi_x_i) risk_phi = risk_phi + array_sum_to_scalar(phi_i) risk_phi_x = risk_phi_x + matrix_axis_0_sum_to_array(phi_x_i) risk_phi_x_x = risk_phi_x_x + phi_x_x_i deaths = E[slice_] tied_death_counts = array_sum_to_scalar(deaths.astype(int)) if tied_death_counts == 0: pos -= count_of_removals continue xi_deaths = X_at_t[deaths] weights_deaths = weights_at_t[deaths] x_death_sum = matrix_axis_0_sum_to_array(weights_deaths[:, None] * xi_deaths) weight_count = array_sum_to_scalar(weights_deaths) weighted_average = weight_count / tied_death_counts if tied_death_counts > 1: tie_phi = array_sum_to_scalar(phi_i[deaths]) tie_phi_x = matrix_axis_0_sum_to_array(phi_x_i[deaths]) tie_phi_x_x = np.dot(xi_deaths.T, phi_i[deaths] * xi_deaths) increasing_proportion = np.arange(tied_death_counts) / tied_death_counts denom = 1.0 / (risk_phi - increasing_proportion * tie_phi) numer = risk_phi_x - np.outer(increasing_proportion, tie_phi_x) a1 = np.einsum("ab,i->ab", risk_phi_x_x, denom) - np.einsum( "ab,i->ab", tie_phi_x_x, increasing_proportion * denom ) else: denom = 1.0 / np.array([risk_phi]) numer = risk_phi_x a1 = risk_phi_x_x * denom summand = numer * denom[:, None] a2 = summand.T.dot(summand) gradient = gradient + x_death_sum - weighted_average * summand.sum(0) log_lik = log_lik + np.dot(x_death_sum, beta) + weighted_average * np.log(denom).sum() hessian = hessian + weighted_average * (a2 - a1) pos -= count_of_removals return hessian, gradient, log_lik
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_treeify'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '25', '44', '61', '101', '105', '109', '115', '166']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '12'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'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': 'empty_like'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'last_full_row'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '43'], 'value': '-'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'log2'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '42'], 'value': '+'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'len_ragged_row'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '52'], 'value': '-'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '52', 'type': 'parenthesized_expression', 'children': ['53']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '60'], 'value': '-'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '**'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '56', 'type': 'parenthesized_expression', 'children': ['57']}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '+'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'last_full_row'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '>'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len_ragged_row'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'block', 'children': ['66', '80', '91']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'bottom_row_ix'}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 's_'}, {'id': '73', 'type': 'slice', 'children': ['74', '75', '78', '79']}; {'id': '74', 'type': 'colon', 'children': []}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '*'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len_ragged_row'}; {'id': '78', 'type': 'colon', 'children': []}, {'id': '79', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '88']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '84', 'type': 'slice', 'children': ['85', '87']}, {'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'len_ragged_row'}, {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'bottom_row_ix'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'bottom_row_ix'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'values_start'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'values_space'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'values_len'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '**'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'last_full_row'}, {'id': '115', 'type': 'while_statement', 'children': ['116', '122']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '<'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'values_start'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '122', 'type': 'block', 'children': ['123', '144', '153', '157']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '137']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '127', 'type': 'slice', 'children': ['128', '131', '132']}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '-'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'values_len'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'colon', 'children': []}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '136'], 'value': '-'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '*'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'values_len'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '139', 'type': 'slice', 'children': ['140', '141', '142', '143']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'values_start'}, {'id': '141', 'type': 'colon', 'children': []}; {'id': '142', 'type': 'colon', 'children': []}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'values_space'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'augmented_assignment', 'children': ['146', '147'], 'value': '+='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'values_start'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '/'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'values_space'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'augmented_assignment', 'children': ['155', '156'], 'value': '*='}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'values_space'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'values_len'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '/'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'values_len'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'tree'}
def _treeify(values): if len(values) == 1: return values tree = np.empty_like(values) last_full_row = int(np.log2(len(values) + 1) - 1) len_ragged_row = len(values) - (2 ** (last_full_row + 1) - 1) if len_ragged_row > 0: bottom_row_ix = np.s_[: 2 * len_ragged_row : 2] tree[-len_ragged_row:] = values[bottom_row_ix] values = np.delete(values, bottom_row_ix) values_start = 0 values_space = 2 values_len = 2 ** last_full_row while values_start < len(values): tree[values_len - 1 : 2 * values_len - 1] = values[values_start::values_space] values_start += int(values_space / 2) values_space *= 2 values_len = int(values_len / 2) return tree
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nearest_neighbors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'top_k'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '9', 'type': 'block', 'children': ['10', '16', '24', '38', '53']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'point'}, {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '23'], 'value': '-'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'vectors'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'point'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'top_ids'}, {'id': '41', 'type': 'subscript', 'children': ['42', '47']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'distances'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'slice', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'top_k'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '62']}, {'id': '55', 'type': 'subscript', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'vocabulary'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'id_word'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'}
def nearest_neighbors(self, word, top_k=10): point = self[word] diff = self.vectors - point distances = np.linalg.norm(diff, axis=1) top_ids = distances.argsort()[1:top_k+1] return [self.vocabulary.id_word[i] for i in top_ids]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_range'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'soft_range'}, {'id': '7', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'try_statement', 'children': ['10', '91']}; {'id': '10', 'type': 'block', 'children': ['11', '20', '39', '56', '77']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'}; {'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': 'array'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '23', 'type': 'conditional_expression', 'children': ['24', '30', '38'], 'value': 'if'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'squeeze'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '37'], 'value': '>'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '44']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'soft_range'}; {'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': 'values'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'list', 'children': ['54', '55'], 'value': '[values, soft_range]'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'soft_range'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '64']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '63'], 'value': '=='}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'M'"}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'expression_list', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'expression_list', 'children': ['79', '85']}, {'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': 'nanmin'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'nanmax'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '91', 'type': 'except_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'try_statement', 'children': ['94', '111']}; {'id': '94', 'type': 'block', 'children': ['95', '102']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'tuple', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '109', 'type': 'unary_operator', 'children': ['110'], 'value': '-'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'except_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'tuple', 'children': ['115', '116']}, {'id': '115', 'type': 'None', 'children': []}
def find_range(values, soft_range=[]): try: values = np.array(values) values = np.squeeze(values) if len(values.shape) > 1 else values if len(soft_range): values = np.concatenate([values, soft_range]) if values.dtype.kind == 'M': return values.min(), values.max() return np.nanmin(values), np.nanmax(values) except: try: values = sorted(values) return (values[0], values[-1]) except: return (None, None)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dimension_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'odict'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'kdims'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'vdims'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '20', '26', '57', '77', '143']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sortkws'}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ndims'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kdims'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dimensions'}, {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kdims'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'vdims'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '54']}; {'id': '30', 'type': 'tuple', 'children': ['31', '34', '43']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'dimensions'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ndims'}, {'id': '43', 'type': 'conditional_expression', 'children': ['44', '45', '51'], 'value': 'if'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ndims'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '-'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ndims'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key_index'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cached_values'}; {'id': '60', 'type': 'dictionary_comprehension', 'children': ['61', '74']}, {'id': '61', 'type': 'pair', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '68'], 'value': '+'}; {'id': '66', 'type': 'list', 'children': ['67'], 'value': '[None]'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dimensions'}, {'id': '77', 'type': 'if_statement', 'children': ['78', '90', '96']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '86'], 'value': '!='}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'key_index'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Cannot sort on duplicated dimensions"'}; {'id': '96', 'type': 'else_clause', 'children': ['97']}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sortkws'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'key'"}, {'id': '103', 'type': 'lambda', 'children': ['104', '106']}; {'id': '104', 'type': 'lambda_parameters', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '108', 'type': 'generator_expression', 'children': ['109', '132']}, {'id': '109', 'type': 'conditional_expression', 'children': ['110', '124', '127'], 'value': 'if'}; {'id': '110', 'type': 'call', 'children': ['111', '118']}, {'id': '111', 'type': 'attribute', 'children': ['112', '117']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cached_values'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'subscript', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '127', 'type': 'subscript', 'children': ['128', '131']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '132', 'type': 'for_in_clause', 'children': ['133', '139']}, {'id': '133', 'type': 'pattern_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '135', 'type': 'tuple_pattern', 'children': ['136', '137', '138']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'indexes'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '151', '163']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '150'], 'value': '=='}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'version_info'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'major'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'return_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'python2sort'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '161']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'odict'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'dictionary_splat', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sortkws'}, {'id': '163', 'type': 'else_clause', 'children': ['164']}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '174']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'odict'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'dictionary_splat', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'sortkws'}
def dimension_sort(odict, kdims, vdims, key_index): sortkws = {} ndims = len(kdims) dimensions = kdims+vdims indexes = [(dimensions[i], int(i not in range(ndims)), i if i in range(ndims) else i-ndims) for i in key_index] cached_values = {d.name: [None]+list(d.values) for d in dimensions} if len(set(key_index)) != len(key_index): raise ValueError("Cannot sort on duplicated dimensions") else: sortkws['key'] = lambda x: tuple(cached_values[dim.name].index(x[t][d]) if dim.values else x[t][d] for i, (dim, t, d) in enumerate(indexes)) if sys.version_info.major == 3: return python2sort(odict.items(), **sortkws) else: return sorted(odict.items(), **sortkws)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_topologically'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '17', '38', '143', '152']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'levels_by_name'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'names_by_level'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '17', 'type': 'function_definition', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'function_name', 'children': [], 'value': 'add_level_to_name'}, {'id': '19', 'type': 'parameters', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '22', 'type': 'block', 'children': ['23', '29']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'levels_by_name'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'names_by_level'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '38', 'type': 'function_definition', 'children': ['39', '40', '42']}, {'id': '39', 'type': 'function_name', 'children': [], 'value': 'walk_depth_first'}; {'id': '40', 'type': 'parameters', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '42', 'type': 'block', 'children': ['43', '48']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[name]'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '48', 'type': 'while_statement', 'children': ['49', '51']}, {'id': '49', 'type': 'parenthesized_expression', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '51', 'type': 'block', 'children': ['52', '60', '66', '87', '93', '105', '123', '137']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'levels_by_name'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'continue_statement', 'children': []}; {'id': '66', 'type': 'if_statement', 'children': ['67', '75']}, {'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'or'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '75', 'type': 'block', 'children': ['76', '80', '86']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'add_level_to_name'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '86', 'type': 'continue_statement', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'children_not_calculated'}; {'id': '96', 'type': 'list_comprehension', 'children': ['97', '98', '101']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '101', 'type': 'if_clause', 'children': ['102']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'not'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'levels_by_name'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'children_not_calculated'}, {'id': '107', 'type': 'block', 'children': ['108', '115', '122']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'children_not_calculated'}; {'id': '122', 'type': 'continue_statement', 'children': []}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '130', 'type': 'generator_expression', 'children': ['131', '134']}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'levels_by_name'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'lname'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'lname'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'add_level_to_name'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'walk_depth_first'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '152', 'type': 'return_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'takewhile'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '167']}, {'id': '161', 'type': 'lambda', 'children': ['162', '164']}; {'id': '162', 'type': 'lambda_parameters', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'generator_expression', 'children': ['168', '175']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'names_by_level'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '174', 'type': 'None', 'children': []}, {'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '181', 'type': 'argument_list', 'children': []}
def sort_topologically(graph): levels_by_name = {} names_by_level = defaultdict(list) def add_level_to_name(name, level): levels_by_name[name] = level names_by_level[level].append(name) def walk_depth_first(name): stack = [name] while(stack): name = stack.pop() if name in levels_by_name: continue if name not in graph or not graph[name]: level = 0 add_level_to_name(name, level) continue children = graph[name] children_not_calculated = [child for child in children if child not in levels_by_name] if children_not_calculated: stack.append(name) stack.extend(children_not_calculated) continue level = 1 + max(levels_by_name[lname] for lname in children) add_level_to_name(name, level) for name in graph: walk_depth_first(name) return list(itertools.takewhile(lambda x: x is not None, (names_by_level.get(i, None) for i in itertools.count())))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'layer_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hmap'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '89']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'orderings'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hmap'}, {'id': '13', 'type': 'block', 'children': ['14', '35']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'okeys'}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '24']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_overlay_spec'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '28']}, {'id': '25', 'type': 'pattern_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'v'}; {'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': 'o'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '49', '58']}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '43'], 'value': 'and'}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '42'], 'value': '=='}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'okeys'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'in'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'okeys'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'orderings'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'orderings'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'okeys'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'orderings'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'dictionary_comprehension', 'children': ['67', '76']}, {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '69', 'type': 'conditional_expression', 'children': ['70', '71', '74'], 'value': 'if'}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '74', 'type': 'list', 'children': ['75'], 'value': '[v]'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '80']}, {'id': '77', 'type': 'pattern_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '88']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'okeys'}, {'id': '85', 'type': 'slice', 'children': ['86', '87']}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'okeys'}, {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '92', '98']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_topologically'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'orderings'}; {'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'g'}
def layer_sort(hmap): orderings = {} for o in hmap: okeys = [get_overlay_spec(o, k, v) for k, v in o.data.items()] if len(okeys) == 1 and not okeys[0] in orderings: orderings[okeys[0]] = [] else: orderings.update({k: [] if k == v else [v] for k, v in zip(okeys[1:], okeys)}) return [i for g in sort_topologically(orderings) for i in sorted(g)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'arglexsort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '5', 'type': 'block', 'children': ['6', '22', '39', '56']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dtypes'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'string', 'children': [], 'value': "','"}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '13', 'type': 'generator_expression', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'arrays'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'recarray'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '36']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dtypes'}, {'id': '39', 'type': 'for_statement', 'children': ['40', '43', '47']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '55']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'recarray'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '%'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'f%s'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'recarray'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '61', 'type': 'argument_list', 'children': []}
def arglexsort(arrays): dtypes = ','.join(array.dtype.str for array in arrays) recarray = np.empty(len(arrays[0]), dtype=dtypes) for i, array in enumerate(arrays): recarray['f%s' % i] = array return recarray.argsort()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'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': 'by'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '36', '49']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16', '23']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kdims'}, {'id': '23', 'type': 'elif_clause', 'children': ['24', '30']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '34', 'type': 'list', 'children': ['35'], 'value': '[by]'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted_columns'}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'clone'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted_columns'}
def sort(self, by=None, reverse=False): if by is None: by = self.kdims elif not isinstance(by, list): by = [by] sorted_columns = self.interface.sort(self, by, reverse) return self.clone(sorted_columns)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'glyph_order'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'draw_order'}, {'id': '7', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '60']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '16', 'type': 'function_definition', 'children': ['17', '18', '20']}, {'id': '17', 'type': 'function_name', 'children': [], 'value': 'order_fn'}; {'id': '18', 'type': 'parameters', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '20', 'type': 'block', 'children': ['21', '36']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '29']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'draw_order'}, {'id': '29', 'type': 'if_clause', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'parenthesized_expression', 'children': ['38']}; {'id': '38', 'type': 'conditional_expression', 'children': ['39', '49', '50'], 'value': 'if'}, {'id': '39', 'type': 'tuple', 'children': ['40', '48']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'draw_order'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'matches'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '50', 'type': 'tuple', 'children': ['51', '59']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'}; {'id': '52', 'type': 'float', 'children': [], 'value': '1e9'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'order_fn'}
def glyph_order(keys, draw_order=[]): keys = sorted(keys) def order_fn(glyph): matches = [item for item in draw_order if glyph.startswith(item)] return ((draw_order.index(matches[0]), glyph) if matches else (1e9+keys.index(glyph), glyph)) return sorted(keys, key=order_fn)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_coords'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '34', '44', '63', '69', '73', '187', '248']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'xdim'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ydim'}; {'id': '12', 'type': 'subscript', 'children': ['13', '21']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dimensions'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'colon', 'children': []}, {'id': '23', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'xcoords'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'dimension_values'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'xdim'}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ycoords'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dimension_values'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ydim'}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'grouped'}, {'id': '47', 'type': 'call', 'children': ['48', '62']}; {'id': '48', 'type': 'attribute', 'children': ['49', '61']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'xdim'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'container_type'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'group_type'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'Dataset'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'}; {'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': 'orderings'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'True', 'children': []}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'grouped'}; {'id': '76', 'type': 'block', 'children': ['77', '87', '140']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dimension_values'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ydim'}; {'id': '86', 'type': 'False', 'children': []}, {'id': '87', 'type': 'if_statement', 'children': ['88', '94', '106']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '93'], 'value': '=='}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '102']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'orderings'}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'list', 'children': ['103'], 'value': '[vals[0]]'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '119']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '118'], 'value': '-'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '119', 'type': 'block', 'children': ['120', '133']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'pattern_list', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'p2'}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '127', 'type': 'slice', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '129', 'type': 'colon', 'children': []}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'orderings'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '138', 'type': 'list', 'children': ['139'], 'value': '[p2]'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'if_statement', 'children': ['144', '153', '170']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '150'], 'value': 'in'}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '150', 'type': 'tuple', 'children': ['151', '152']}, {'id': '151', 'type': 'string', 'children': [], 'value': "'i'"}; {'id': '152', 'type': 'string', 'children': [], 'value': "'f'"}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '157', 'type': 'call', 'children': ['158', '169']}; {'id': '158', 'type': 'attribute', 'children': ['159', '168']}, {'id': '159', 'type': 'parenthesized_expression', 'children': ['160']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '167'], 'value': '>='}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '169', 'type': 'argument_list', 'children': []}; {'id': '170', 'type': 'else_clause', 'children': ['171']}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'array_equal'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '186']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '187', 'type': 'if_statement', 'children': ['188', '195', '205']}; {'id': '188', 'type': 'boolean_operator', 'children': ['189', '190'], 'value': 'or'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'one_to_one'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'orderings'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ycoords'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ycoords'}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ycoords'}, {'id': '205', 'type': 'elif_clause', 'children': ['206', '211']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'is_cyclic'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'orderings'}, {'id': '211', 'type': 'block', 'children': ['212', '228']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'list_splat', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'sort_topologically'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'orderings'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'ycoords'}, {'id': '231', 'type': 'conditional_expression', 'children': ['232', '233', '242'], 'value': 'if'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '238'], 'value': '=='}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'ycoords'}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ycoords'}; {'id': '248', 'type': 'return_statement', 'children': ['249']}, {'id': '249', 'type': 'expression_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'xcoords'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ycoords'}
def _get_coords(self, obj): xdim, ydim = obj.dimensions(label=True)[:2] xcoords = obj.dimension_values(xdim, False) ycoords = obj.dimension_values(ydim, False) grouped = obj.groupby(xdim, container_type=OrderedDict, group_type=Dataset).values() orderings = OrderedDict() sort = True for group in grouped: vals = group.dimension_values(ydim, False) if len(vals) == 1: orderings[vals[0]] = [vals[0]] else: for i in range(len(vals)-1): p1, p2 = vals[i:i+2] orderings[p1] = [p2] if sort: if vals.dtype.kind in ('i', 'f'): sort = (np.diff(vals)>=0).all() else: sort = np.array_equal(np.sort(vals), vals) if sort or one_to_one(orderings, ycoords): ycoords = np.sort(ycoords) elif not is_cyclic(orderings): coords = list(itertools.chain(*sort_topologically(orderings))) ycoords = coords if len(coords) == len(ycoords) else np.sort(ycoords) return xcoords, ycoords
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'most_frequent_terms'}, {'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': 'count'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '31', '43']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'terms'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '22']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_terms'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '24', 'type': 'lambda', 'children': ['25', '27']}, {'id': '25', 'type': 'lambda_parameters', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'terms'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '36', 'type': 'generator_expression', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'terms'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '47', '50', '61']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'terms'}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '>'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'terms'}; {'id': '58', 'type': 'slice', 'children': ['59', '60']}, {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'raise_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"Only non-negative values are allowed for count of terms."'}
def most_frequent_terms(self, count=0): terms = sorted(self._terms.items(), key=lambda i: -i[1]) terms = tuple(i[0] for i in terms) if count == 0: return terms elif count > 0: return terms[:count] else: raise ValueError( "Only non-negative values are allowed for count of terms.")
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_values'}, {'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': 'ascending'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '15', '101']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'is'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'index_type'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '28', '40', '51', '65', '81']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'index_expr'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'column_expr'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'zip_expr'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'zip_columns'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'list', 'children': ['49', '50'], 'value': '[index_expr, column_expr]'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'index_expr'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'column_expr'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'result_expr'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61', '64']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'zip_expr'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'weld_type'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'unzip_expr'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'unzip_columns'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'result_expr'}; {'id': '74', 'type': 'list', 'children': ['75', '78'], 'value': '[self.index_type, self.weld_type]'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'index_type'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'weld_type'}, {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'SeriesWeld'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '89', '92', '95', '98']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'unzip_expr'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'weld_type'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'column_name'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'index_type'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '101', 'type': 'else_clause', 'children': ['102']}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'result_expr'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'grizzly_impl'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'expr'}
def sort_values(self, ascending=False): if self.index_type is not None: index_expr = grizzly_impl.get_field(self.expr, 0) column_expr = grizzly_impl.get_field(self.expr, 1) zip_expr = grizzly_impl.zip_columns([index_expr, column_expr]) result_expr = grizzly_impl.sort(zip_expr, 1, self.weld_type, ascending) unzip_expr = grizzly_impl.unzip_columns( result_expr, [self.index_type, self.weld_type] ) return SeriesWeld( unzip_expr, self.weld_type, self.df, self.column_name, self.index_type, self.index_name ) else: result_expr = grizzly_impl.sort(self.expr)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'keytype'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '32', '53', '70', '82', '98']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'WeldObject'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'encoder_'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'decoder_'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'expr_var'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'WeldObject'}; {'id': '38', 'type': 'block', 'children': ['39', '45']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'expr_var'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'obj_id'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '52']}, {'id': '47', 'type': 'subscript', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'expr_var'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57', '64']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key_str'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"x.$%s"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'key_str'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"x"'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '73']}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key_str'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '+'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'key_str'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '%'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"* %s(-1)"'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'keytype'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'weld_template'}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'weld_code'}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'weld_template'}, {'id': '91', 'type': 'dictionary', 'children': ['92', '95']}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': '"expr"'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'expr_var'}, {'id': '95', 'type': 'pair', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"key"'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'key_str'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'weld_obj'}
def sort(expr, field = None, keytype=None, ascending=True): weld_obj = WeldObject(encoder_, decoder_) expr_var = weld_obj.update(expr) if isinstance(expr, WeldObject): expr_var = expr.obj_id weld_obj.dependencies[expr_var] = expr if field is not None: key_str = "x.$%s" % field else: key_str = "x" if not ascending: key_str = key_str + "* %s(-1)" % keytype weld_template = weld_obj.weld_code = weld_template % {"expr":expr_var, "key":key_str} return weld_obj
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expand_filename_pattern'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'base_dir'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sourcefile'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '21', '28', '34', '48', '58', '64', '76']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'substitute_vars'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '19', '20']}, {'id': '17', 'type': 'list', 'children': ['18'], 'value': '[pattern]'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sourcefile'}, {'id': '21', 'type': 'assert_statement', 'children': ['22']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '=='}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '!='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"Expanded variables in expression %r to %r."'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'fileList'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'expand_filename_pattern'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'expandedPattern'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'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': 'fileList'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '67']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fileList'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"No files found matching %r."'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fileList'}
def expand_filename_pattern(self, pattern, base_dir, sourcefile=None): expandedPattern = substitute_vars([pattern], self, sourcefile) assert len(expandedPattern) == 1 expandedPattern = expandedPattern[0] if expandedPattern != pattern: logging.debug("Expanded variables in expression %r to %r.", pattern, expandedPattern) fileList = util.expand_filename_pattern(expandedPattern, base_dir) fileList.sort() if not fileList: logging.warning("No files found matching %r.", pattern) return fileList
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_file_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'shortFile'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '32', '41', '65']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'in'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"://"'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'shortFile'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'list', 'children': ['13'], 'value': '[shortFile]'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'shortFile'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'expandedFile'}, {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'expandvars'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '30']}, {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'shortFile'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fileList'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'expandedFile'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '48', '55']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '47'], 'value': '!='}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'fileList'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'fileList'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'else_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"No file matches \'%s\'."'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'shortFile'}, {'id': '65', 'type': 'return_statement', 'children': ['66']}
def get_file_list(shortFile): if "://" in shortFile: return [shortFile] expandedFile = os.path.expandvars(os.path.expanduser(shortFile)) fileList = glob.glob(expandedFile) if len(fileList) != 0: fileList.sort() else: logging.warning("No file matches '%s'.", shortFile) return fileList
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'FPS'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'explicit_name'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '29']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_make_name'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '20', '26']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '20', 'type': 'conditional_expression', 'children': ['21', '22', '25'], 'value': 'if'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'explicit_name'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'explicit_name'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'FP_'"}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'FP'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37', '41', '44']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'FPS'"}; {'id': '34', 'type': 'tuple', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '39', 'type': 'set', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'symbolic'}, {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort'}
def FPS(name, sort, explicit_name=None): n = _make_name(name, sort.length, False if explicit_name is None else explicit_name, prefix='FP_') return FP('FPS', (n, sort), variables={n}, symbolic=True, length=sort.length)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_fp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'rm'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '25']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rm'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'rm'}; {'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': 'fp'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'RM'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fpToFP'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rm'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'}
def to_fp(self, sort, rm=None): if rm is None: rm = fp.RM.default() return fpToFP(rm, self, sort)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'val_to_fp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'rm'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '30', '50', '61']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'rm'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rm'}, {'id': '21', 'type': 'call', 'children': ['22', '29']}; {'id': '22', 'type': 'attribute', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'RM'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '38', 'type': 'call', 'children': ['39', '46']}, {'id': '39', 'type': 'attribute', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fp'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'FSort'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'from_size'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '53', 'type': 'conditional_expression', 'children': ['54', '57', '58'], 'value': 'if'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'fpToFP'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'signed'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'fpToFPUnsigned'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'rm'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort'}
def val_to_fp(self, sort, signed=True, rm=None): if rm is None: rm = fp.fp.RM.default() if sort is None: sort = fp.fp.FSort.from_size(self.length) op = fp.fpToFP if signed else fp.fpToFPUnsigned return op(rm, self, sort)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_orbitals'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'element_pdos'}, {'id': '5', 'type': 'block', 'children': ['6', '29', '37', '41', '57']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_orbitals'}, {'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28'], 'value': "['s', 'p', 'py', 'pz', 'px',\n 'd', 'dxy', 'dyz', 'dz2', 'dxz', 'dx2',\n 'f', 'f_3', 'f_2', 'f_1', 'f_0', 'f1', 'f2', 'f3']"}; {'id': '10', 'type': 'string', 'children': [], 'value': "'s'"}, {'id': '11', 'type': 'string', 'children': [], 'value': "'p'"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'py'"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'pz'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'px'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'d'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'dxy'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'dyz'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'dz2'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'dxz'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'dx2'"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'f'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'f_3'"}, {'id': '23', 'type': 'string', 'children': [], 'value': "'f_2'"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'f_1'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'f_0'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'f1'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'f2'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'f3'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'unsorted_keys'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'element_pdos'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '40', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_orbitals'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'unsorted_keys'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def sort_orbitals(element_pdos): sorted_orbitals = ['s', 'p', 'py', 'pz', 'px', 'd', 'dxy', 'dyz', 'dz2', 'dxz', 'dx2', 'f', 'f_3', 'f_2', 'f_1', 'f_0', 'f1', 'f2', 'f3'] unsorted_keys = element_pdos.keys() sorted_keys = [] for key in sorted_orbitals: if key in unsorted_keys: sorted_keys.append(key) return sorted_keys
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_vasprun_files'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '25', '29', '111']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'folders'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'string', 'children': [], 'value': "'split-*'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'folders'}, {'id': '17', 'type': 'conditional_expression', 'children': ['18', '22', '23'], 'value': 'if'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'folders'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'folders'}, {'id': '23', 'type': 'list', 'children': ['24'], 'value': "['.']"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fol'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'folders'}; {'id': '32', 'type': 'block', 'children': ['33', '45', '57']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'vr_file'}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'fol'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'vasprun.xml'"}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'vr_file_gz'}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fol'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'vasprun.xml.gz'"}, {'id': '57', 'type': 'if_statement', 'children': ['58', '66', '74', '91']}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'vr_file'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'filenames'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'vr_file'}; {'id': '74', 'type': 'elif_clause', 'children': ['75', '83']}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'vr_file_gz'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'vr_file_gz'}, {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93', '105']}, {'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': 'logging'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'ERROR: No vasprun.xml found in {}!'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'fol'}, {'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': 'sys'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'return_statement', 'children': ['112']}
def find_vasprun_files(): folders = glob.glob('split-*') folders = sorted(folders) if folders else ['.'] filenames = [] for fol in folders: vr_file = os.path.join(fol, 'vasprun.xml') vr_file_gz = os.path.join(fol, 'vasprun.xml.gz') if os.path.exists(vr_file): filenames.append(vr_file) elif os.path.exists(vr_file_gz): filenames.append(vr_file_gz) else: logging.error('ERROR: No vasprun.xml found in {}!'.format(fol)) sys.exit() return filenames
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'feed'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'byts'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '18', '22', '74']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Feed bytes to the unpacker and return completed objects.\n Args:\n byts (bytes): Bytes to unpack.\n Notes:\n It is intended that this function is called multiple times with\n bytes from some sort of a stream, as it will unpack and return\n objects as they are available.\n Returns:\n list: List of tuples containing the item size and the unpacked item.\n '''"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'unpk'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'feed'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'byts'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'retn'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'while_statement', 'children': ['23', '24']}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'try_statement', 'children': ['26', '66']}; {'id': '26', 'type': 'block', 'children': ['27', '37', '47', '60']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'unpk'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'unpack'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '40', 'type': 'call', 'children': ['41', '46']}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'unpk'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'retn'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'tuple', 'children': ['54', '59']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'item'}; {'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': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '66', 'type': 'except_clause', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'msgpack'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'OutOfData'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'break_statement', 'children': []}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'retn'}
def feed(self, byts): ''' Feed bytes to the unpacker and return completed objects. Args: byts (bytes): Bytes to unpack. Notes: It is intended that this function is called multiple times with bytes from some sort of a stream, as it will unpack and return objects as they are available. Returns: list: List of tuples containing the item size and the unpacked item. ''' self.unpk.feed(byts) retn = [] while True: try: item = self.unpk.unpack() tell = self.unpk.tell() retn.append((tell - self.size, item)) self.size = tell except msgpack.exceptions.OutOfData: break return retn
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'maximum_consecutive_dry_days'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pr'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'thresh'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'1 mm/day'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'YS'"}, {'id': '11', 'type': 'block', 'children': ['12', '14', '25', '39']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'convert_units_to'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'thresh'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pr'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'hydro'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '28', 'type': 'call', 'children': ['29', '35']}, {'id': '29', 'type': 'attribute', 'children': ['30', '34']}; {'id': '30', 'type': 'parenthesized_expression', 'children': ['31']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '<'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pr'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'resample'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'rl'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'longest_run'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dim'}
def maximum_consecutive_dry_days(pr, thresh='1 mm/day', freq='YS'): r t = utils.convert_units_to(thresh, pr, 'hydro') group = (pr < t).resample(time=freq) return group.apply(rl.longest_run, dim='time')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'daily_downsampler'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'YS'"}; {'id': '8', 'type': 'block', 'children': ['9', '11', '108', '127', '135', '242', '250', '260']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'if_statement', 'children': ['12', '25', '68']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '22']}, {'id': '15', 'type': 'subscript', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'datetime64'}, {'id': '25', 'type': 'block', 'children': ['26', '47']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'years'}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '36']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'{:04d}'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '38', 'type': 'attribute', 'children': ['39', '46']}, {'id': '39', 'type': 'attribute', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dt'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'months'}; {'id': '50', 'type': 'list_comprehension', 'children': ['51', '57']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'{:02d}'"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '59', 'type': 'attribute', 'children': ['60', '67']}; {'id': '60', 'type': 'attribute', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '68', 'type': 'else_clause', 'children': ['69']}, {'id': '69', 'type': 'block', 'children': ['70', '89']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'years'}, {'id': '73', 'type': 'list_comprehension', 'children': ['74', '82']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'{:04d}'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'months'}; {'id': '92', 'type': 'list_comprehension', 'children': ['93', '101']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'{:02d}'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'month'}, {'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'seasons'}, {'id': '111', 'type': 'list_comprehension', 'children': ['112', '124']}; {'id': '112', 'type': 'subscript', 'children': ['113', '118']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': "'DJF DJF MAM MAM MAM JJA JJA JJA SON SON SON DJF'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '123'], 'value': '-'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'for_in_clause', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'months'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'n_t'}; {'id': '130', 'type': 'attribute', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '139', '144', '166', '230']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '=='}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'YS'"}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'l_tags'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'years'}; {'id': '144', 'type': 'elif_clause', 'children': ['145', '148']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'MS'"}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'l_tags'}; {'id': '152', 'type': 'list_comprehension', 'children': ['153', '160']}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '+'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'years'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'months'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'n_t'}; {'id': '166', 'type': 'elif_clause', 'children': ['167', '170']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '169', 'type': 'string', 'children': [], 'value': "'QS-DEC'"}; {'id': '170', 'type': 'block', 'children': ['171', '175', '226']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ys'}; {'id': '174', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '175', 'type': 'for_statement', 'children': ['176', '177', '181']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'n_t'}, {'id': '181', 'type': 'block', 'children': ['182', '188', '194', '200', '217']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'months'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'seasons'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'years'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'12'"}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '216'], 'value': '+'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ys'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '+'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'l_tags'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ys'}; {'id': '230', 'type': 'else_clause', 'children': ['231']}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'raise_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'freqency {:s} not implemented'"}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '257']}; {'id': '252', 'type': 'subscript', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'tags'"}, {'id': '257', 'type': 'tuple', 'children': ['258', '259']}; {'id': '258', 'type': 'string', 'children': [], 'value': "'time'"}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'l_tags'}; {'id': '260', 'type': 'return_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}
def daily_downsampler(da, freq='YS'): r if isinstance(da.time.values[0], np.datetime64): years = ['{:04d}'.format(y) for y in da.time.dt.year.values] months = ['{:02d}'.format(m) for m in da.time.dt.month.values] else: years = ['{:04d}'.format(v.year) for v in da.time.values] months = ['{:02d}'.format(v.month) for v in da.time.values] seasons = ['DJF DJF MAM MAM MAM JJA JJA JJA SON SON SON DJF'.split()[int(m) - 1] for m in months] n_t = da.time.size if freq == 'YS': l_tags = years elif freq == 'MS': l_tags = [years[i] + months[i] for i in range(n_t)] elif freq == 'QS-DEC': ys = [] for i in range(n_t): m = months[i] s = seasons[i] y = years[i] if m == '12': y = str(int(y) + 1) ys.append(y + s) l_tags = ys else: raise RuntimeError('freqency {:s} not implemented'.format(freq)) buffer = da.copy() buffer.coords['tags'] = ('time', l_tags) return buffer.groupby('tags')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'identify_vertex_neighbours'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vertex'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '26', '47', '54']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'simplices'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'simplices'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ridx'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cidx'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '=='}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'simplices'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'vertex'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'neighbour_array'}, {'id': '29', 'type': 'call', 'children': ['30', '46']}; {'id': '30', 'type': 'attribute', 'children': ['31', '45']}, {'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': 'unique'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hstack'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'list', 'children': ['42'], 'value': '[simplices[ridx]]'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'simplices'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ridx'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'neighbour_array'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'vertex'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'neighbour_array'}
def identify_vertex_neighbours(self, vertex): simplices = self.simplices ridx, cidx = np.where(simplices == vertex) neighbour_array = np.unique(np.hstack([simplices[ridx]])).tolist() neighbour_array.remove(vertex) return neighbour_array
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_encode'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '18', '27', '41']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'''Encode the results of this paged response as JSON writing to the\n provided file-like `out` object. This function will iteratively read\n as many pages as present, streaming the contents out as JSON.\n :param file-like out: an object with a `write` function\n :param int limit: optional maximum number of items to write\n :param bool sort_keys: if True, output keys sorted, default is False\n :param bool indent: if True, indent output, default is False\n '''"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'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': '_json_stream'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'enc'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'JSONEncoder'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '38']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '49']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'enc'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'iterencode'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'}, {'id': '57', 'type': 'string', 'children': [], 'value': "u'%s'"}
def json_encode(self, out, limit=None, sort_keys=False, indent=None): '''Encode the results of this paged response as JSON writing to the provided file-like `out` object. This function will iteratively read as many pages as present, streaming the contents out as JSON. :param file-like out: an object with a `write` function :param int limit: optional maximum number of items to write :param bool sort_keys: if True, output keys sorted, default is False :param bool indent: if True, indent output, default is False ''' stream = self._json_stream(limit) enc = json.JSONEncoder(indent=indent, sort_keys=sort_keys) for chunk in enc.iterencode(stream): out.write(u'%s' % chunk)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'quick_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '20', '29']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Execute a quick search with the specified request.\n :param request: see :ref:`api-search-request`\n :param **kw: See Options below\n :returns: :py:class:`planet.api.models.Items`\n :raises planet.api.exceptions.APIException: On API error.\n :Options:\n * page_size (int): Size of response pages\n * sort (string): Sorting order in the form `field (asc|desc)`\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_params'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '68']}, {'id': '31', 'type': 'attribute', 'children': ['32', '67']}; {'id': '32', 'type': 'call', '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': 'dispatcher'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'response'}; {'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': 'models'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Request'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '50', '53', '56', '61', '64']}; {'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': '_url'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'data/v1/quick-search'"}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'auth'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'body_type'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'Items'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get_body'}
def quick_search(self, request, **kw): '''Execute a quick search with the specified request. :param request: see :ref:`api-search-request` :param **kw: See Options below :returns: :py:class:`planet.api.models.Items` :raises planet.api.exceptions.APIException: On API error. :Options: * page_size (int): Size of response pages * sort (string): Sorting order in the form `field (asc|desc)` ''' body = json.dumps(request) params = self._params(kw) return self.dispatcher.response(models.Request( self._url('data/v1/quick-search'), self.auth, params=params, body_type=models.Items, data=body, method='POST')).get_body()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'saved_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '17', '26']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Execute a saved search by search id.\n :param sid string: The id of the search\n :returns: :py:class:`planet.api.models.Items`\n :raises planet.api.exceptions.APIException: On API error.\n :Options:\n * page_size (int): Size of response pages\n * sort (string): Sorting order in the form `field (asc|desc)`\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '%'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'data/v1/searches/%s/results'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sid'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'params'}; {'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': '_params'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '49']}; {'id': '28', 'type': 'attribute', 'children': ['29', '48']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_get'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '40', '45']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_url'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'body_type'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Items'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_body'}, {'id': '49', 'type': 'argument_list', 'children': []}
def saved_search(self, sid, **kw): '''Execute a saved search by search id. :param sid string: The id of the search :returns: :py:class:`planet.api.models.Items` :raises planet.api.exceptions.APIException: On API error. :Options: * page_size (int): Size of response pages * sort (string): Sorting order in the form `field (asc|desc)` ''' path = 'data/v1/searches/%s/results' % sid params = self._params(kw) return self._get(self._url(path), body_type=models.Items, params=params).get_body()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortValue_isItalic'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '18', '29', '40']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'styleMapStyleName'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'styleMapStyleName'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'styleMapStyleName'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"italic"'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'styleMapStyleName'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '37']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '34'], 'value': 'not'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'italicAngle'}; {'id': '34', 'type': 'tuple', 'children': ['35', '36']}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}
def _sortValue_isItalic(font): info = font.info styleMapStyleName = info.styleMapStyleName if styleMapStyleName is not None and "italic" in styleMapStyleName: return 0 if info.italicAngle not in (None, 0): return 0 return 1
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortValue_isMonospace'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '24', '28', '54']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'attribute', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'postscriptIsFixedPitch'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'testWidth'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36', '43']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'testWidth'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'testWidth'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'width'}, {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '51']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '!='}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'testWidth'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'width'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}
def _sortValue_isMonospace(font): if font.info.postscriptIsFixedPitch: return 0 if not len(font): return 1 testWidth = None for glyph in font: if testWidth is None: testWidth = glyph.width else: if testWidth != glyph.width: return 1 return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flair_template_sync'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'editable'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'static'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'use_css'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '11', 'type': 'block', 'children': ['12', '24', '30', '50', '54', '116', '138', '219', '228', '268', '278', '290']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '16'], 'value': 'and'}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'use_text'}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'use_css'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'At least one of use_text or use_css must be True'"}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '27', 'type': 'tuple', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'alpha'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'size'"}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'Sort must be one of: {}'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'counter'}, {'id': '53', 'type': 'dictionary', 'children': []}; {'id': '54', 'type': 'if_statement', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'static'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'static'}; {'id': '60', 'type': 'block', 'children': ['61', '110']}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'and'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'use_css'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '65', 'type': 'block', 'children': ['66', '85', '106']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '71', 'type': 'generator_expression', 'children': ['72', '77']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': "','"}, {'id': '85', 'type': 'if_statement', 'children': ['86', '92']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '91'], 'value': '!='}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'raise_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '104']}; {'id': '98', 'type': 'attribute', 'children': ['99', '103']}, {'id': '99', 'type': 'concatenated_string', 'children': ['100', '101', '102']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'--static argument {!r} must have two '"}, {'id': '101', 'type': 'string', 'children': [], 'value': "'parts (comma separated) when using '"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'both text and css.'"}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '120', 'type': 'block', 'children': ['121', '130']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'Retrieving current flair\\n'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '137']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '145']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'flair'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'current_flair'}; {'id': '144', 'type': 'argument_list', 'children': []}, {'id': '145', 'type': 'block', 'children': ['146', '168', '200']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '150', 'type': 'block', 'children': ['151', '160']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '158']}, {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'if_statement', 'children': ['169', '172', '183', '192']}, {'id': '169', 'type': 'boolean_operator', 'children': ['170', '171'], 'value': 'and'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'use_css'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '176', 'type': 'tuple', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'flair'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'flair_text'"}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'flair'}; {'id': '182', 'type': 'string', 'children': [], 'value': "'flair_css_class'"}, {'id': '183', 'type': 'elif_clause', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '189', 'type': 'subscript', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'flair'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'flair_text'"}; {'id': '192', 'type': 'else_clause', 'children': ['193']}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'flair'}, {'id': '199', 'type': 'string', 'children': [], 'value': "'flair_css_class'"}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204', '211']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'augmented_assignment', 'children': ['207', '210'], 'value': '+='}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'counter'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '211', 'type': 'else_clause', 'children': ['212']}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '218']}, {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'counter'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '218', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '219', 'type': 'if_statement', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '227', 'type': 'argument_list', 'children': []}; {'id': '228', 'type': 'if_statement', 'children': ['229', '232', '244']}, {'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': '=='}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '231', 'type': 'string', 'children': [], 'value': "'alpha'"}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '251', 'type': 'argument_list', 'children': ['252', '257', '265']}; {'id': '252', 'type': 'call', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'counter'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '256', 'type': 'argument_list', 'children': []}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '259', 'type': 'lambda', 'children': ['260', '262']}; {'id': '260', 'type': 'lambda_parameters', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '267', 'type': 'True', 'children': []}; {'id': '268', 'type': 'if_statement', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'string', 'children': [], 'value': "'Clearing current flair templates'"}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'call', 'children': ['280', '289']}; {'id': '280', 'type': 'attribute', 'children': ['281', '288']}, {'id': '281', 'type': 'attribute', 'children': ['282', '287']}; {'id': '282', 'type': 'attribute', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'flair'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'templates'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'clear'}, {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'for_statement', 'children': ['291', '294', '295']}, {'id': '291', 'type': 'pattern_list', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '295', 'type': 'block', 'children': ['296', '310', '342', '358']}; {'id': '296', 'type': 'if_statement', 'children': ['297', '303']}, {'id': '297', 'type': 'boolean_operator', 'children': ['298', '300'], 'value': 'or'}; {'id': '298', 'type': 'not_operator', 'children': ['299']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '<'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '303', 'type': 'block', 'children': ['304', '309']}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'string', 'children': [], 'value': "'a'"}, {'id': '309', 'type': 'continue_statement', 'children': []}; {'id': '310', 'type': 'if_statement', 'children': ['311', '314', '321', '332']}, {'id': '311', 'type': 'boolean_operator', 'children': ['312', '313'], 'value': 'and'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'use_css'}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '320']}, {'id': '317', 'type': 'pattern_list', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'css'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '321', 'type': 'elif_clause', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'use_text'}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '329']}; {'id': '326', 'type': 'pattern_list', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'css'}, {'id': '329', 'type': 'expression_list', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '331', 'type': 'string', 'children': [], 'value': "''"}; {'id': '332', 'type': 'else_clause', 'children': ['333']}, {'id': '333', 'type': 'block', 'children': ['334']}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'assignment', 'children': ['336', '339']}; {'id': '336', 'type': 'pattern_list', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'css'}, {'id': '339', 'type': 'expression_list', 'children': ['340', '341']}; {'id': '340', 'type': 'string', 'children': [], 'value': "''"}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '342', 'type': 'if_statement', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '346', 'type': 'block', 'children': ['347']}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'string', 'children': [], 'value': "'Adding template: text: {!r} css: {!r}'"}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '355', 'type': 'argument_list', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'css'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'call', 'children': ['360', '369']}; {'id': '360', 'type': 'attribute', 'children': ['361', '368']}, {'id': '361', 'type': 'attribute', 'children': ['362', '367']}; {'id': '362', 'type': 'attribute', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'flair'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'templates'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '369', 'type': 'argument_list', 'children': ['370', '371', '372']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'css'}
def flair_template_sync(self, editable, limit, static, sort, use_css, use_text): if not use_text and not use_css: raise Exception('At least one of use_text or use_css must be True') sorts = ('alpha', 'size') if sort not in sorts: raise Exception('Sort must be one of: {}'.format(', '.join(sorts))) counter = {} if static: for key in static: if use_css and use_text: parts = tuple(x.strip() for x in key.split(',')) if len(parts) != 2: raise Exception('--static argument {!r} must have two ' 'parts (comma separated) when using ' 'both text and css.'.format(parts)) key = parts counter[key] = limit if self.verbose: sys.stdout.write('Retrieving current flair\n') sys.stdout.flush() for flair in self.current_flair(): if self.verbose: sys.stdout.write('.') sys.stdout.flush() if use_text and use_css: key = (flair['flair_text'], flair['flair_css_class']) elif use_text: key = flair['flair_text'] else: key = flair['flair_css_class'] if key in counter: counter[key] += 1 else: counter[key] = 1 if self.verbose: print() if sort == 'alpha': items = sorted(counter.items()) else: items = sorted(counter.items(), key=lambda x: x[1], reverse=True) if self.verbose: print('Clearing current flair templates') self.sub.flair.templates.clear() for key, count in items: if not key or count < limit: print('a') continue if use_text and use_css: text, css = key elif use_text: text, css = key, '' else: text, css = '', key if self.verbose: print('Adding template: text: {!r} css: {!r}' .format(text, css)) self.sub.flair.templates.add(text, css, editable)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'props'}, {'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': 'element'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'deep'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '17', '28', '35', '52', '71', '128', '184', '213', '222', '244', '256', '266', '346']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'element'}; {'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': '_parse_element'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'allowed_modes'}, {'id': '31', 'type': 'list', 'children': ['32', '33', '34'], 'value': "['all', 'constants', 'models']"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'all'"}, {'id': '33', 'type': 'string', 'children': [], 'value': "'constants'"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'models'"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'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': '_parse_mode'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46', '49']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'allowed'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'allowed_modes'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'single'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'all'"}; {'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': 'vals'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'props'"}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '=='}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'constants'"}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '82', '112']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '82', 'type': 'block', 'children': ['83', '97']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'props'"}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'props'"}; {'id': '128', 'type': 'if_statement', 'children': ['129', '132']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '=='}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '139', '169']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'models'"}, {'id': '139', 'type': 'block', 'children': ['140', '154']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'props'"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '168']}, {'id': '163', 'type': 'attribute', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'else_clause', 'children': ['170']}; {'id': '170', 'type': 'block', 'children': ['171', '178']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'string', 'children': [], 'value': "'Object does not have a models attribute'"}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '183', 'type': 'argument_list', 'children': []}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'hide'}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'list_comprehension', 'children': ['191', '192', '199']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '192', 'type': 'for_in_clause', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '198', 'type': 'argument_list', 'children': []}, {'id': '199', 'type': 'if_clause', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '211']}, {'id': '201', 'type': 'attribute', 'children': ['202', '210']}; {'id': '202', 'type': 'subscript', 'children': ['203', '209']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'hide'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'temp'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'list_comprehension', 'children': ['229', '230', '233']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '233', 'type': 'if_clause', 'children': ['234']}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '243'], 'value': 'not'}, {'id': '235', 'type': 'subscript', 'children': ['236', '242']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '242', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '247', 'type': 'call', 'children': ['248', '254']}; {'id': '248', 'type': 'attribute', 'children': ['249', '253']}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'PrintableList'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '266', 'type': 'if_statement', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '268', 'type': 'block', 'children': ['269', '307']}, {'id': '269', 'type': 'if_statement', 'children': ['270', '276']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': '_isa'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'string', 'children': [], 'value': "'phase'"}; {'id': '276', 'type': 'block', 'children': ['277']}, {'id': '277', 'type': 'for_statement', 'children': ['278', '279', '289']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '279', 'type': 'call', 'children': ['280', '285']}; {'id': '280', 'type': 'attribute', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'find_physics'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'phase'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'augmented_assignment', 'children': ['292', '293'], 'value': '+='}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'vals'}, {'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': 'props'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '301', '304']}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '301', 'type': 'keyword_argument', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'deep'}; {'id': '306', 'type': 'False', 'children': []}, {'id': '307', 'type': 'if_statement', 'children': ['308', '314']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': '_isa'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}, {'id': '313', 'type': 'string', 'children': [], 'value': "'network'"}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'for_statement', 'children': ['316', '317', '328']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '317', 'type': 'call', 'children': ['318', '327']}; {'id': '318', 'type': 'attribute', 'children': ['319', '326']}, {'id': '319', 'type': 'call', 'children': ['320', '325']}; {'id': '320', 'type': 'attribute', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'geometries'}, {'id': '325', 'type': 'argument_list', 'children': []}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '327', 'type': 'argument_list', 'children': []}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'augmented_assignment', 'children': ['331', '332'], 'value': '+='}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '340', '343']}, {'id': '337', 'type': 'keyword_argument', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'deep'}, {'id': '345', 'type': 'False', 'children': []}; {'id': '346', 'type': 'return_statement', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'vals'}
def props(self, element=None, mode='all', deep=False): r element = self._parse_element(element=element) allowed_modes = ['all', 'constants', 'models'] mode = self._parse_mode(mode=mode, allowed=allowed_modes, single=True) if mode == 'all': vals = set(self.keys(mode='props')) if mode == 'constants': if hasattr(self, 'models'): temp = set(self.keys(mode='props')) vals = temp.difference(self.models.keys()) else: vals = set(self.keys(mode='props')) if mode == 'models': if hasattr(self, 'models'): temp = set(self.keys(mode='props')) vals = temp.intersection(self.models.keys()) else: logger.warning('Object does not have a models attribute') vals = set() hide = set([i for i in self.keys() if i.split('.')[1].startswith('_')]) vals = vals.difference(hide) temp = set([i for i in vals if i.split('.')[0] not in element]) vals = set(vals).difference(temp) vals = PrintableList(list(vals)) if deep: if self._isa('phase'): for item in self.project.find_physics(phase=self): vals += item.props(element=element, mode=mode, deep=False) if self._isa('network'): for item in self.project.geometries().values(): vals += item.props(element=element, mode=mode, deep=False) return vals
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_residual'}, {'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': 'pores'}, {'id': '7', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '14', '23', '32', '40', '46', '54', '60', '70', '84', '95', '298', '312']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Ps'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_parse_indices'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pores'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'overwrite'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'pore.residual'"}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'pore.residual'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Ps'}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'residual'}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'pore.residual'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'net'}, {'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': 'project'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'conns'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'net'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'throat.conns'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rclusters'}, {'id': '63', 'type': 'attribute', 'children': ['64', '69']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'site_percolation'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'conns'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'residual'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sites'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'rcluster_ids'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'rclusters'}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '>'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'rclusters'}; {'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'initial_num'}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '94'], 'value': '-'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'rcluster_id'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'rcluster_ids'}; {'id': '98', 'type': 'block', 'children': ['99', '105', '118', '127', '161', '169', '177', '194', '202', '210', '218', '229', '240', '257']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rPs'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '=='}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'rclusters'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rcluster_id'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'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': 'unique'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'pore.cluster'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'rPs'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '125', 'type': 'unary_operator', 'children': ['126'], 'value': '-'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '134', '141']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '133'], 'value': '>'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cluster_num'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143', '152']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cluster_num'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '164', 'type': 'subscript', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cluster_num'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '176']}, {'id': '171', 'type': 'subscript', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'pore.cluster'"}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'rPs'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cluster_num'}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'Ts'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'net'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'find_neighbor_throats'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '188', '191']}, {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'pores'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'rPs'}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '190', 'type': 'True', 'children': []}, {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'xnor'"}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '201']}; {'id': '196', 'type': 'subscript', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'string', 'children': [], 'value': "'throat.cluster'"}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'Ts'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'cluster_num'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '209']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'pore.invasion_sequence'"}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'rPs'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '217']}; {'id': '212', 'type': 'subscript', 'children': ['213', '216']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'throat.invasion_sequence'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'Ts'}, {'id': '217', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '225']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'pore.invasion_pressure'"}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'rPs'}, {'id': '225', 'type': 'unary_operator', 'children': ['226'], 'value': '-'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '236']}, {'id': '231', 'type': 'subscript', 'children': ['232', '235']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'throat.invasion_pressure'"}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'Ts'}; {'id': '236', 'type': 'unary_operator', 'children': ['237'], 'value': '-'}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'Ts'}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'net'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'find_neighbor_throats'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '251', '254']}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'pores'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'rPs'}, {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '253', 'type': 'True', 'children': []}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'exclusive_or'"}, {'id': '257', 'type': 'for_statement', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'Ts'}; {'id': '260', 'type': 'block', 'children': ['261', '265', '276', '283', '290']}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '264', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'subscript', 'children': ['272', '275']}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'throat.entry_pressure'"}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'T'}, {'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': 'data'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}, {'id': '289', 'type': 'string', 'children': [], 'value': "'throat'"}; {'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': 'hq'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'heappush'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'assignment', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'invasion_running'}, {'id': '303', 'type': 'binary_operator', 'children': ['304', '306'], 'value': '*'}; {'id': '304', 'type': 'list', 'children': ['305'], 'value': '[True]'}, {'id': '305', 'type': 'True', 'children': []}; {'id': '306', 'type': 'call', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '312', 'type': 'for_statement', 'children': ['313', '314', '323']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'c_num'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'if_statement', 'children': ['325', '328']}, {'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': '>'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'c_num'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'initial_num'}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '336']}, {'id': '331', 'type': 'subscript', 'children': ['332', '335']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'invasion_running'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'c_num'}
def set_residual(self, pores=[], overwrite=False): r Ps = self._parse_indices(pores) if overwrite: self['pore.residual'] = False self['pore.residual'][Ps] = True residual = self['pore.residual'] net = self.project.network conns = net['throat.conns'] rclusters = site_percolation(conns, residual).sites rcluster_ids = np.unique(rclusters[rclusters > -1]) initial_num = len(self.queue)-1 for rcluster_id in rcluster_ids: rPs = rclusters == rcluster_id existing = np.unique(self['pore.cluster'][rPs]) existing = existing[existing > -1] if len(existing) > 0: cluster_num = existing[0] else: cluster_num = len(self.queue) self.queue.append([]) queue = self.queue[cluster_num] self['pore.cluster'][rPs] = cluster_num Ts = net.find_neighbor_throats(pores=rPs, flatten=True, mode='xnor') self['throat.cluster'][Ts] = cluster_num self['pore.invasion_sequence'][rPs] = 0 self['throat.invasion_sequence'][Ts] = 0 self['pore.invasion_pressure'][rPs] = -np.inf self['throat.invasion_pressure'][Ts] = -np.inf Ts = net.find_neighbor_throats(pores=rPs, flatten=True, mode='exclusive_or') for T in Ts: data = [] data.append(self['throat.entry_pressure'][T]) data.append(T) data.append('throat') hq.heappush(queue, data) self.invasion_running = [True]*len(self.queue) for c_num in range(len(self.queue)): if c_num > initial_num: self.invasion_running[c_num] = False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'results'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'Pc'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '17', '25', '29', '43', '57']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Psatn'}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '16'], 'value': '<='}, {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'pore.invasion_pressure'"}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Pc'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Tsatn'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '<='}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'string', 'children': [], 'value': "'throat.invasion_pressure'"}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Pc'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'inv_phase'}; {'id': '28', 'type': 'dictionary', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'inv_phase'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'pore.occupancy'"}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sp'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Psatn'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'inv_phase'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'throat.occupancy'"}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sp'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'Tsatn'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def results(self, Pc): r Psatn = self['pore.invasion_pressure'] <= Pc Tsatn = self['throat.invasion_pressure'] <= Pc inv_phase = {} inv_phase['pore.occupancy'] = sp.array(Psatn, dtype=float) inv_phase['throat.occupancy'] = sp.array(Tsatn, dtype=float) return inv_phase
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'folderitems'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '22', '35', '42']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'BaseView'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'folderitems'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fill_empty_slots'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"pos_sortkey"'}, {'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': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'fill_slots_headers'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'items'}
def folderitems(self): items = BaseView.folderitems(self) self.fill_empty_slots(items) items = sorted(items, key=itemgetter("pos_sortkey")) self.fill_slots_headers(items) return items
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resort_client_actions'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'portal'}, {'id': '5', 'type': 'block', 'children': ['6', '21', '32', '49', '66', '86', '96']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_actions'}, {'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'], 'value': '[\n "edit",\n "contacts",\n "view",\n "analysisrequests",\n "batches",\n "samplepoints",\n "profiles",\n "templates",\n "specs",\n "orders",\n "reports_listing"\n ]'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"edit"'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"contacts"'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"view"'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"analysisrequests"'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"batches"'}, {'id': '15', 'type': 'string', 'children': [], 'value': '"samplepoints"'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"profiles"'}, {'id': '17', 'type': 'string', 'children': [], 'value': '"templates"'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"specs"'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"orders"'}; {'id': '20', 'type': 'string', 'children': [], 'value': '"reports_listing"'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'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': 'portal'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'portal_types'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'getTypeInfo'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Client"'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '46']}; {'id': '38', 'type': 'lambda', 'children': ['39', '41']}, {'id': '39', 'type': 'lambda_parameters', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': 'in'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted_actions'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_actions'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '63']}, {'id': '55', 'type': 'lambda', 'children': ['56', '58']}; {'id': '56', 'type': 'lambda_parameters', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': 'not'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sorted_actions'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'type_info'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_actions'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '75', 'type': 'lambda', 'children': ['76', '78']}; {'id': '76', 'type': 'lambda_parameters', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sorted_actions'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'missing'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'type_info'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_actions'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'actions'}
def resort_client_actions(portal): sorted_actions = [ "edit", "contacts", "view", "analysisrequests", "batches", "samplepoints", "profiles", "templates", "specs", "orders", "reports_listing" ] type_info = portal.portal_types.getTypeInfo("Client") actions = filter(lambda act: act.id in sorted_actions, type_info._actions) missing = filter(lambda act: act.id not in sorted_actions, type_info._actions) actions = sorted(actions, key=lambda act: sorted_actions.index(act.id)) if missing: actions.extend(missing) type_info._actions = actions
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reindex_sortable_title'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'portal'}, {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'catalogs'}, {'id': '9', 'type': 'list', 'children': ['10', '11', '12'], 'value': '[\n "bika_catalog",\n "bika_setup_catalog",\n "portal_catalog",\n ]'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"bika_catalog"'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"bika_setup_catalog"'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"portal_catalog"'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'catalog_name'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'catalogs'}; {'id': '16', 'type': 'block', 'children': ['17', '29', '38', '47', '58']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'string', 'children': [], 'value': '"Reindexing sortable_title for {} ..."'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'catalog_name'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ZLogHandler'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'steps'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'catalog'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_tool'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'catalog_name'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'catalog'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'reindexIndex'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"sortable_title"'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pghandler'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'commit_transaction'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}
def reindex_sortable_title(portal): catalogs = [ "bika_catalog", "bika_setup_catalog", "portal_catalog", ] for catalog_name in catalogs: logger.info("Reindexing sortable_title for {} ...".format(catalog_name)) handler = ZLogHandler(steps=100) catalog = api.get_tool(catalog_name) catalog.reindexIndex("sortable_title", None, pghandler=handler) commit_transaction(portal)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'folderitems'}, {'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': 'full_objects'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'classic'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '22', '36', '65', '77', '120']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'bsc'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'getToolByName'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '21', 'type': 'string', 'children': [], 'value': '"bika_setup_catalog"'}; {'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': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'an_cats'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bsc'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '33']}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'portal_type'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"AnalysisCategory"'}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '35', 'type': 'string', 'children': [], 'value': '"sortable_title"'}; {'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': 'an_cats_order'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '55']}, {'id': '45', 'type': 'tuple', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Title'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"{:04}"'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '55', 'type': 'for_in_clause', 'children': ['56', '59']}; {'id': '56', 'type': 'pattern_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'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': 'an_cats'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '68', 'type': 'call', 'children': ['69', '76']}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'AnalysisServicesView'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'folderitems'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81', '110']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'do_cats'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'categories'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '96']}; {'id': '90', 'type': 'lambda', 'children': ['91', '93']}, {'id': '91', 'type': 'lambda_parameters', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '104', 'type': 'lambda', 'children': ['105', '107']}, {'id': '105', 'type': 'lambda_parameters', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'else_clause', 'children': ['111']}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'items'}
def folderitems(self, full_objects=False, classic=True): bsc = getToolByName(self.context, "bika_setup_catalog") self.an_cats = bsc( portal_type="AnalysisCategory", sort_on="sortable_title") self.an_cats_order = dict([ (b.Title, "{:04}".format(a)) for a, b in enumerate(self.an_cats)]) items = super(AnalysisServicesView, self).folderitems() if self.do_cats: self.categories = map(lambda x: x[0], sorted(self.categories, key=lambda x: x[1])) else: self.categories.sort() return items
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_display_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"key"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'allow_empty'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '18', '31', '68', '79', '105']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dl'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DisplayList'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '28', 'type': 'list', 'children': ['29', '30'], 'value': '[pairs, pairs]'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pair'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '34', 'type': 'block', 'children': ['35', '52']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '43']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '40', 'type': 'tuple', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'dl'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list_splat', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '58']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pair'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '58', 'type': 'block', 'children': ['59', '67']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dl'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'list_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '67', 'type': 'break_statement', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'allow_empty'}; {'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': 'dl'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '""'}; {'id': '78', 'type': 'string', 'children': [], 'value': '""'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83', '92']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"key"'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'dl'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dl'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sortedByKey'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '95', 'type': 'string', 'children': [], 'value': '"value"'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dl'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dl'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sortedByValue'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'return_statement', 'children': ['106']}
def to_display_list(pairs, sort_by="key", allow_empty=True): dl = DisplayList() if isinstance(pairs, basestring): pairs = [pairs, pairs] for pair in pairs: if isinstance(pair, (tuple, list)): dl.add(*pair) if isinstance(pair, basestring): dl.add(*pairs) break if allow_empty: dl.add("", "") if sort_by == "key": dl = dl.sortedByKey() elif sort_by == "value": dl = dl.sortedByValue() return dl
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortable_title'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '25']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'plone_sortable_title'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'safe_callable'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'lower'}
def sortable_title(instance): title = plone_sortable_title(instance) if safe_callable(title): title = title() return title.lower()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortable_sortkey_title'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '25', '33', '42']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sortable_title'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '18']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'safe_callable'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'getSortKey'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '999999'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"{:010.3f}{}"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'title'}
def sortable_sortkey_title(instance): title = sortable_title(instance) if safe_callable(title): title = title() sort_key = instance.getSortKey() if sort_key is None: sort_key = 999999 return "{:010.3f}{}".format(sort_key, title)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_analyses'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'analyses'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '44', '48', '52', '56', '105', '112', '119']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'analyses'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'analyses'}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'lambda', 'children': ['17', '19']}, {'id': '17', 'type': 'lambda_parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'an'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'an'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'getRequestID'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'function_definition', 'children': ['25', '26', '28']}, {'id': '25', 'type': 'function_name', 'children': [], 'value': 'sorted_by_sortkey'}; {'id': '26', 'type': 'parameters', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'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': 'an'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'an'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'getPrioritySortkey'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'current_sample_id'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}, {'id': '51', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted_analyses'}, {'id': '55', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'analysis'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'analyses'}, {'id': '59', 'type': 'block', 'children': ['60', '68', '97', '104']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sample_id'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'analysis'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'getRequestID'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '74']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '71'], 'value': 'and'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sample_id'}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '!='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'current_sample_id'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sample_id'}; {'id': '74', 'type': 'block', 'children': ['75', '82', '89', '93']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sorted_by_sortkey'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted_analyses'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'current_sample_id'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sample_id'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}; {'id': '96', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'analysis'}; {'id': '104', 'type': 'continue_statement', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sorted_by_sortkey'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}; {'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': 'sorted_analyses'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'current_analyses'}, {'id': '119', 'type': 'return_statement', 'children': ['120']}
def sorted_analyses(self, analyses): analyses = sorted(analyses, key=lambda an: an.getRequestID()) def sorted_by_sortkey(objs): return sorted(objs, key=lambda an: an.getPrioritySortkey()) current_sample_id = None current_analyses = [] sorted_analyses = [] for analysis in analyses: sample_id = analysis.getRequestID() if sample_id and current_sample_id != sample_id: current_analyses = sorted_by_sortkey(current_analyses) sorted_analyses.extend(current_analyses) current_sample_id = sample_id current_analyses = [] current_analyses.append(analysis) continue current_analyses = sorted_by_sortkey(current_analyses) sorted_analyses.extend(current_analyses) return sorted_analyses
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_attachments'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '21', '29', '93', '103']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"inf"'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'order'}; {'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_attachments_order'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'attachments'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_attachments'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'function_definition', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'function_name', 'children': [], 'value': 'att_cmp'}, {'id': '31', 'type': 'parameters', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'att1'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'att2'}; {'id': '34', 'type': 'block', 'children': ['35', '44', '53', '70', '87']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'att1'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'UID'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_n2'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'att2'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'UID'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_i1'}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '69'], 'value': 'or'}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'and'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '68'], 'value': '+'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': '_i2'}, {'id': '73', 'type': 'boolean_operator', 'children': ['74', '86'], 'value': 'or'}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '78'], 'value': 'and'}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '_n2'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '85'], 'value': '+'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_n2'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': '_i1'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_i2'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sorted_attachments'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'attachments'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'att_cmp'}, {'id': '103', 'type': 'return_statement', 'children': ['104']}
def get_sorted_attachments(self): inf = float("inf") order = self.get_attachments_order() attachments = self.get_attachments() def att_cmp(att1, att2): _n1 = att1.get('UID') _n2 = att2.get('UID') _i1 = _n1 in order and order.index(_n1) + 1 or inf _i2 = _n2 in order and order.index(_n2) + 1 or inf return cmp(_i1, _i2) sorted_attachments = sorted(attachments, cmp=att_cmp) return sorted_attachments
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_analyses_at'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '23', '29', '37', '77']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'to_int'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'slot'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '<'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'slot'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'analyses'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'getLayout'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'layout'}; {'id': '40', 'type': 'block', 'children': ['41', '50', '56', '65']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'layout_slot'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'to_int'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'position'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'uid'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'analysis_uid'"}; {'id': '56', 'type': 'if_statement', 'children': ['57', '63']}, {'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'or'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '!='}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'layout_slot'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'slot'}, {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'uid'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'continue_statement', 'children': []}, {'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': 'analyses'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get_object_by_uid'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'uid'}, {'id': '77', 'type': 'return_statement', 'children': ['78']}
def get_analyses_at(self, slot): slot = to_int(slot) if slot < 1: return list() analyses = list() layout = self.getLayout() for pos in layout: layout_slot = to_int(pos['position']) uid = pos['analysis_uid'] if layout_slot != slot or not uid: continue analyses.append(api.get_object_by_uid(uid)) return analyses
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rejectionOptionsList'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '14', '20', '42', '53', '65', '69', '86']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'string', 'children': [], 'value': '"Return a sorted list with the options defined in bikasetup"'}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'plone'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'getSite'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'plone'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'bika_setup'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '29', '38']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '28'], 'value': '>'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'settings'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'RejectionReasons'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'reject_reasons'}, {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'RejectionReasons'}, {'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': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'reject_reasons'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'checkbox'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}, {'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': 'sorted_keys'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'checkbox'"}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '68', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reject_reasons'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'items'}
def rejectionOptionsList(self): "Return a sorted list with the options defined in bikasetup" plone = getSite() settings = plone.bika_setup if len(settings.RejectionReasons) > 0: reject_reasons = settings.RejectionReasons[0] else: return [] sorted_keys = sorted(reject_reasons.keys()) if 'checkbox' in sorted_keys: sorted_keys.remove('checkbox') items = [] for key in sorted_keys: items.append(reject_reasons[key].strip()) return items
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_cond_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys_list'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '30', '36']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'cond_list'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'keys_list'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'analysisservice-'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'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': 'cond_list'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'cond_list'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cond_list'}
def _get_sorted_cond_keys(self, keys_list): cond_list = [] for key in keys_list: if key.startswith('analysisservice-'): cond_list.append(key) cond_list.sort() return cond_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_sorted_action_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys_list'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '30', '36']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'action_list'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'keys_list'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'action-'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'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': 'action_list'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'action_list'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'action_list'}
def _get_sorted_action_keys(self, keys_list): action_list = [] for key in keys_list: if key.startswith('action-'): action_list.append(key) action_list.sort() return action_list
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getLinkedRequests'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '25', '44', '52']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_tool'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"reference_catalog"'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'refs'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rc'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getBackReferences'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"AnalysisRequestAttachment"'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ars'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '43']}, {'id': '31', 'type': 'lambda', 'children': ['32', '34']}; {'id': '32', 'type': 'lambda_parameters', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_object_by_uid'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sourceUID'}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'refs'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ars'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ars'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57', '62']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ars'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get_path'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def getLinkedRequests(self): rc = api.get_tool("reference_catalog") refs = rc.getBackReferences(self, "AnalysisRequestAttachment") ars = map(lambda ref: api.get_object_by_uid(ref.sourceUID, None), refs) ars = filter(None, ars) return sorted(ars, key=api.get_path, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getLinkedAnalyses'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '31', '39']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'refs'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'get_backreferences'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"AnalysisAttachment"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ans'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '30']}; {'id': '20', 'type': 'lambda', 'children': ['21', '23']}, {'id': '21', 'type': 'lambda_parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'uid'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_object_by_uid'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'uid'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'refs'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ans'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ans'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '49']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ans'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_path'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '51', 'type': 'True', 'children': []}
def getLinkedAnalyses(self): refs = get_backreferences(self, "AnalysisAttachment") ans = map(lambda uid: api.get_object_by_uid(uid, None), refs) ans = filter(None, ans) return sorted(ans, key=api.get_path, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_fields'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '21', '83']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"inf"'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'order'}; {'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_field_order'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'function_definition', 'children': ['22', '23', '26']}; {'id': '22', 'type': 'function_name', 'children': [], 'value': 'field_cmp'}, {'id': '23', 'type': 'parameters', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'field1'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'field2'}; {'id': '26', 'type': 'block', 'children': ['27', '35', '43', '60', '77']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'field1'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'getName'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_n2'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'field2'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'getName'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_i1'}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '59'], 'value': 'or'}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'and'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '58'], 'value': '+'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_n1'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_i2'}, {'id': '63', 'type': 'boolean_operator', 'children': ['64', '76'], 'value': 'or'}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '68'], 'value': 'and'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_n2'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '75'], 'value': '+'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_n2'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_i1'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_i2'}, {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '92']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_fields'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cmp'}
def get_sorted_fields(self): inf = float("inf") order = self.get_field_order() def field_cmp(field1, field2): _n1 = field1.getName() _n2 = field2.getName() _i1 = _n1 in order and order.index(_n1) + 1 or inf _i2 = _n2 in order and order.index(_n2) + 1 or inf return cmp(_i1, _i2) return sorted(self.get_fields(), cmp=field_cmp)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_sorting'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '21', '33', '43', '124']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': '"sidx"'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'or'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'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': 'get'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"sort_on"'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '42'], 'value': 'or'}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"Title"'}, {'id': '41', 'type': 'string', 'children': [], 'value': '"sortable_title"'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '45', 'type': 'block', 'children': ['46', '52', '62', '74', '97', '115']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '50', 'type': 'string', 'children': [], 'value': '"sort_on"'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_order'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"sord"'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort_order'}, {'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'or'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort_order'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"sort_order"'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '82', '89']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sort_order'}, {'id': '77', 'type': 'list', 'children': ['78', '79', '80', '81'], 'value': '["desc", "reverse", "rev", "descending"]'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"desc"'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"reverse"'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"rev"'}, {'id': '81', 'type': 'string', 'children': [], 'value': '"descending"'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '87', 'type': 'string', 'children': [], 'value': '"sort_order"'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"descending"'}, {'id': '89', 'type': 'else_clause', 'children': ['90']}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sorting'}, {'id': '95', 'type': 'string', 'children': [], 'value': '"sort_order"'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"ascending"'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_limit'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'to_int'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '112']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"limit"'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sort_limit'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sorting'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"sort_limit"'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sort_limit'}; {'id': '124', 'type': 'return_statement', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sorting'}
def resolve_sorting(self, query): sorting = {} sort_on = query.get("sidx", None) sort_on = sort_on or query.get("sort_on", None) sort_on = sort_on == "Title" and "sortable_title" or sort_on if sort_on: sorting["sort_on"] = sort_on sort_order = query.get("sord", None) sort_order = sort_order or query.get("sort_order", None) if sort_order in ["desc", "reverse", "rev", "descending"]: sorting["sort_order"] = "descending" else: sorting["sort_order"] = "ascending" sort_limit = api.to_int(query.get("limit", 30), default=30) if sort_limit: sorting["sort_limit"] = sort_limit return sorting
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_sortable_index'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'index_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'catalog'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '24']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'index'}, {'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_index'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '21']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': 'in'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'meta_type'}, {'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '["FieldIndex", "DateIndex"]'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"FieldIndex"'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"DateIndex"'}
def is_sortable_index(self, index_name, catalog): index = self.get_index(index_name, catalog) if not index: return False return index.meta_type in ["FieldIndex", "DateIndex"]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortable_title'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'portal'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '23', '38', '48', '97']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "''"}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'def_charset'}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'portal'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'plone_utils'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getSiteEncoding'}; {'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': 'sortabletitle'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '37']}; {'id': '30', 'type': 'attribute', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'num_sort_regex'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'zero_fill'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '54']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '50', 'type': 'list', 'children': ['51', '52', '53'], 'value': "[def_charset, 'latin-1', 'utf-8']"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'def_charset'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'latin-1'"}, {'id': '53', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'try_statement', 'children': ['56', '81', '85']}; {'id': '56', 'type': 'block', 'children': ['57', '69', '80']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}; {'id': '60', 'type': 'subscript', 'children': ['61', '66']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'safe_unicode'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'charset'}; {'id': '66', 'type': 'slice', 'children': ['67', '68']}, {'id': '67', 'type': 'colon', 'children': []}; {'id': '68', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '79'], 'value': 'or'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'def_charset'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '80', 'type': 'break_statement', 'children': []}, {'id': '81', 'type': 'except_clause', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'UnicodeError'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'pass_statement', 'children': []}, {'id': '85', 'type': 'except_clause', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '87', 'type': 'block', 'children': ['88', '96']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sortabletitle'}, {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'colon', 'children': []}, {'id': '95', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '96', 'type': 'break_statement', 'children': []}, {'id': '97', 'type': 'return_statement', 'children': ['98']}
def sortable_title(portal, title): if not title: return '' def_charset = portal.plone_utils.getSiteEncoding() sortabletitle = str(title.lower().strip()) sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle) for charset in [def_charset, 'latin-1', 'utf-8']: try: sortabletitle = safe_unicode(sortabletitle, charset)[:30] sortabletitle = sortabletitle.encode(def_charset or 'utf-8') break except UnicodeError: pass except TypeError: sortabletitle = sortabletitle[:30] break return sortabletitle
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_column'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '7', 'type': 'block', 'children': ['8', '20', '41', '65', '85']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '18']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'in'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'tk'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'DISABLED'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '23', 'type': 'list_comprehension', 'children': ['24', '33']}; {'id': '24', 'type': 'tuple', 'children': ['25', '32']}, {'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': 'set'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_children'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "''"}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '50']}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'lambda', 'children': ['53', '55']}, {'id': '53', 'type': 'lambda_parameters', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_column_types'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'for_statement', 'children': ['66', '71', '75']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '68', 'type': 'tuple_pattern', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'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': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'move'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '83', 'type': 'string', 'children': [], 'value': '""'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'heading'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '94', 'type': 'lambda', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_sort_column'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '101', 'type': 'not_operator', 'children': ['102']}
def _sort_column(self, column, reverse): if tk.DISABLED in self.state(): return l = [(self.set(child, column), child) for child in self.get_children('')] l.sort(reverse=reverse, key=lambda x: self._column_types[column](x[0])) for index, (val, child) in enumerate(l): self.move(child, "", index) self.heading(column, command=lambda: self._sort_column(column, not reverse))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'column'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '11', 'type': 'block', 'children': ['12', '16', '49', '73']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '27']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_column_types'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '27', 'type': 'elif_clause', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '31', 'type': 'block', 'children': ['32', '36']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '43']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_column_types'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '49', 'type': 'if_statement', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', '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': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_visual_drag'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '70', '71']}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ttk'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'Treeview'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '71', 'type': 'dictionary_splat', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '77', '91']}; {'id': '74', 'type': 'boolean_operator', 'children': ['75', '76'], 'value': 'or'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ttk'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'Treeview'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87', '88', '89']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '89', 'type': 'dictionary_splat', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '91', 'type': 'elif_clause', 'children': ['92', '94']}; {'id': '92', 'type': 'not_operator', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '94', 'type': 'block', 'children': ['95', '110', '120']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '98', 'type': 'call', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ttk'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Treeview'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106', '107', '108']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '108', 'type': 'dictionary_splat', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_column_types'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'res'}
def column(self, column, option=None, **kw): config = False if option == 'type': return self._column_types[column] elif 'type' in kw: config = True self._column_types[column] = kw.pop('type') if kw: self._visual_drag.column(ttk.Treeview.column(self, column, 'id'), option, **kw) if kw or option: return ttk.Treeview.column(self, column, option, **kw) elif not config: res = ttk.Treeview.column(self, column, option, **kw) res['type'] = self._column_types[column] return res
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_config_sortable'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortable'}; {'id': '6', 'type': 'block', 'children': ['7', '42']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '12']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '9', 'type': 'subscript', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'string', 'children': [], 'value': '"columns"'}; {'id': '12', 'type': 'block', 'children': ['13', '32']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '16', 'type': 'conditional_expression', 'children': ['17', '30', '31'], 'value': 'if'}, {'id': '17', 'type': 'parenthesized_expression', 'children': ['18']}; {'id': '18', 'type': 'lambda', 'children': ['19', '23']}, {'id': '19', 'type': 'lambda_parameters', 'children': ['20']}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_sort_column'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '29', 'type': 'True', 'children': []}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sortable'}, {'id': '31', 'type': 'string', 'children': [], 'value': '""'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'heading'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_sortable'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sortable'}
def _config_sortable(self, sortable): for col in self["columns"]: command = (lambda c=col: self._sort_column(c, True)) if sortable else "" self.heading(col, command=command) self._sortable = sortable
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_items'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'common_path'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'return_statement', 'children': ['11']}, {'id': '11', 'type': 'generator_expression', 'children': ['12', '13', '22']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'r'}, {'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': '_iter_items'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'repo'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'common_path'}; {'id': '22', 'type': 'if_clause', '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': 'r'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'SymbolicReference'}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'r'}
def iter_items(cls, repo, common_path=None): return (r for r in cls._iter_items(repo, common_path) if r.__class__ == SymbolicReference or not r.is_detached)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_cache'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'extension_data'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ShaStreamCls'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'IndexFileSHA1Writer'}; {'id': '12', 'type': 'block', 'children': ['13', '20', '26', '32', '36', '41', '54', '191', '203']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ShaStreamCls'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tell'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': 'b"DIRC"'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pack'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'string', 'children': [], 'value': '">LL"'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '57', 'type': 'block', 'children': ['58', '64', '71', '78', '84', '94', '103', '115', '126', '156', '161', '176']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'beginoffset'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'tell'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'force_bytes'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'defenc'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'plen'}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '102'], 'value': '&'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'CE_NAMEMASK'}, {'id': '103', 'type': 'assert_statement', 'children': ['104', '110']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'plen'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '%'}, {'id': '111', 'type': 'string', 'children': [], 'value': '"Path %s too long to fit into index"'}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '|'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'plen'}; {'id': '120', 'type': 'parenthesized_expression', 'children': ['121']}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '125'], 'value': '&'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'CE_NAMEMASK_INV'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'pack'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134', '137', '140', '143', '146', '149', '152', '155']}, {'id': '133', 'type': 'string', 'children': [], 'value': '">LLLLLL20sH"'}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '9'}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'flags'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'real_size'}; {'id': '164', 'type': 'parenthesized_expression', 'children': ['165']}, {'id': '165', 'type': 'binary_operator', 'children': ['166', '174'], 'value': '&'}; {'id': '166', 'type': 'parenthesized_expression', 'children': ['167']}, {'id': '167', 'type': 'binary_operator', 'children': ['168', '173'], 'value': '+'}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '172'], 'value': '-'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'tell'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'beginoffset'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '174', 'type': 'unary_operator', 'children': ['175'], 'value': '~'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '*'}, {'id': '181', 'type': 'string', 'children': [], 'value': 'b"\\0"'}; {'id': '182', 'type': 'parenthesized_expression', 'children': ['183']}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '188'], 'value': '-'}; {'id': '184', 'type': 'parenthesized_expression', 'children': ['185']}, {'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'beginoffset'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'real_size'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'tell'}; {'id': '190', 'type': 'argument_list', 'children': []}, {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'extension_data'}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'extension_data'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'stream'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'write_sha'}
def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer): stream = ShaStreamCls(stream) tell = stream.tell write = stream.write version = 2 write(b"DIRC") write(pack(">LL", version, len(entries))) for entry in entries: beginoffset = tell() write(entry[4]) write(entry[5]) path = entry[3] path = force_bytes(path, encoding=defenc) plen = len(path) & CE_NAMEMASK assert plen == len(path), "Path %s too long to fit into index" % entry[3] flags = plen | (entry[2] & CE_NAMEMASK_INV) write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0], entry[8], entry[9], entry[10], entry[1], flags)) write(path) real_size = ((tell() - beginoffset + 8) & ~7) write(b"\0" * ((beginoffset + real_size) - tell())) if extension_data is not None: stream.write(extension_data) stream.write_sha()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_tree_from_cache'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'odb'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sl'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '21', '27', '33', '190', '196', '204', '211', '232']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tree_items'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'tree_items'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sl'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stop'}, {'id': '33', 'type': 'while_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '37', 'type': 'block', 'children': ['38', '44', '56', '60', '72']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '!='}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'UnmergedEntriesError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'augmented_assignment', 'children': ['58', '59'], 'value': '+='}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ci'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rbound'}, {'id': '63', 'type': 'call', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'si'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '77', '96']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '=='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'rbound'}, {'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'tuple', 'children': ['83', '86', '89']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'binsha'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '95', 'type': 'colon', 'children': []}; {'id': '96', 'type': 'else_clause', 'children': ['97']}, {'id': '97', 'type': 'block', 'children': ['98', '109', '113', '158', '178', '186']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '101', 'type': 'subscript', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '105', 'type': 'slice', 'children': ['106', '107', '108']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '107', 'type': 'colon', 'children': []}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'rbound'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'xi'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ci'}, {'id': '113', 'type': 'while_statement', 'children': ['114', '117']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '<'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'xi'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '117', 'type': 'block', 'children': ['118', '124', '136', '154']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'oentry'}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'xi'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'orbound'}, {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'oentry'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'si'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '152']}, {'id': '137', 'type': 'boolean_operator', 'children': ['138', '142'], 'value': 'or'}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'orbound'}; {'id': '140', 'type': 'unary_operator', 'children': ['141'], 'value': '-'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '151'], 'value': '!='}, {'id': '143', 'type': 'subscript', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'oentry'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '147', 'type': 'slice', 'children': ['148', '149', '150']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '149', 'type': 'colon', 'children': []}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'orbound'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'break_statement', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'xi'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'pattern_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sha'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'tree_entry_list'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'write_tree_from_cache'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168', '175']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'odb'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'slice'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '174']}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ci'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'xi'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'rbound'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tree_items_append'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'tuple', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sha'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'S_IFDIR'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ci'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'xi'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'sio'}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'BytesIO'}, {'id': '195', 'type': 'argument_list', 'children': []}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tree_to_stream'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'tree_items'}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sio'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'sio'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'seek'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'istream'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'odb'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'store'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'IStream'}, {'id': '221', 'type': 'argument_list', 'children': ['222', '223', '231']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'str_tree_type'}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'sio'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '230', 'type': 'argument_list', 'children': []}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'sio'}; {'id': '232', 'type': 'return_statement', 'children': ['233']}, {'id': '233', 'type': 'tuple', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'istream'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'binsha'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'tree_items'}
def write_tree_from_cache(entries, odb, sl, si=0): tree_items = [] tree_items_append = tree_items.append ci = sl.start end = sl.stop while ci < end: entry = entries[ci] if entry.stage != 0: raise UnmergedEntriesError(entry) ci += 1 rbound = entry.path.find('/', si) if rbound == -1: tree_items_append((entry.binsha, entry.mode, entry.path[si:])) else: base = entry.path[si:rbound] xi = ci while xi < end: oentry = entries[xi] orbound = oentry.path.find('/', si) if orbound == -1 or oentry.path[si:orbound] != base: break xi += 1 sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) tree_items_append((sha, S_IFDIR, base)) ci = xi sio = BytesIO() tree_to_stream(tree_items, sio.write) sio.seek(0) istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) return (istream.binsha, tree_items)