sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'slug'},{'id': '6', 'type': 'block', 'children': ['7', '16', '21', '29', '42', '55', '68', '81', '94', '107', '115', '123', '167']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_kb_by_slug'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'slug'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'check_knowledge_access'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reqparse'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'RequestParser'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39']},{'id': '35', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '41', 'type': 'string', 'children': [], 'value': '"Return only entries where key matches this."'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52']},{'id': '48', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '54', 'type': 'string', 'children': [], 'value': '"Return only entries where value matches this."'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '65']},{'id': '61', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '67', 'type': 'string', 'children': [], 'value': '"Require a specific page"'},{'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': 'parser'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']},{'id': '74', 'type': 'string', 'children': [], 'value': "'per_page'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '80', 'type': 'string', 'children': [], 'value': '"Set how much result per page"'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91']},{'id': '87', 'type': 'string', 'children': [], 'value': "'match_type'"},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '93', 'type': 'string', 'children': [], 'value': '"s=substring, e=exact, sw=startswith"'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '104']},{'id': '100', 'type': 'string', 'children': [], 'value': "'sortby'"},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '106', 'type': 'string', 'children': [], 'value': '"the sorting criteria (\'from\' or \'to\')"'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'kb_dict'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'to_dict'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'kb_dict'},{'id': '127', 'type': 'string', 'children': [], 'value': "'mappings'"},{'id': '128', 'type': 'call', 'children': ['129', '133']},{'id': '129', 'type': 'attribute', 'children': ['130', '131', '132']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'KnwKBMappingsResource'},{'id': '131', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'search_mappings'},{'id': '133', 'type': 'argument_list', 'children': ['134', '137', '142', '147', '152', '157', '162']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '141', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '146', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'match_type'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '151', 'type': 'string', 'children': [], 'value': "'match_type'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '156', 'type': 'string', 'children': [], 'value': "'sortby'"},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '161', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '166', 'type': 'string', 'children': [], 'value': "'per_page'"},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'kb_dict'}
def get(self, slug): kb = api.get_kb_by_slug(slug) check_knowledge_access(kb) parser = reqparse.RequestParser() parser.add_argument( 'from', type=str, help="Return only entries where key matches this.") parser.add_argument( 'to', type=str, help="Return only entries where value matches this.") parser.add_argument('page', type=int, help="Require a specific page") parser.add_argument('per_page', type=int, help="Set how much result per page") parser.add_argument('match_type', type=str, help="s=substring, e=exact, sw=startswith") parser.add_argument('sortby', type=str, help="the sorting criteria ('from' or 'to')") args = parser.parse_args() kb_dict = kb.to_dict() kb_dict['mappings'] = KnwKBMappingsResource \ .search_mappings(kb=kb, key=args['from'], value=args['to'], match_type=args['match_type'], sortby=args['sortby'], page=args['page'], per_page=args['per_page']) return kb_dict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'slug'},{'id': '6', 'type': 'block', 'children': ['7', '16', '21', '29', '42', '55', '68', '81', '94', '107', '115']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_kb_by_slug'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'slug'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'check_knowledge_access'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reqparse'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'RequestParser'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39']},{'id': '35', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '41', 'type': 'string', 'children': [], 'value': '"Return only entries where \'from\' matches this."'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52']},{'id': '48', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '54', 'type': 'string', 'children': [], 'value': '"Return only entries where \'to\' matches this."'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62', '65']},{'id': '61', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '67', 'type': 'string', 'children': [], 'value': '"Require a specific page"'},{'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': 'parser'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']},{'id': '74', 'type': 'string', 'children': [], 'value': "'per_page'"},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '80', 'type': 'string', 'children': [], 'value': '"Set how much result per page"'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88', '91']},{'id': '87', 'type': 'string', 'children': [], 'value': "'match_type'"},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '93', 'type': 'string', 'children': [], 'value': '"s=substring, e=exact, sw=startswith"'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '104']},{'id': '100', 'type': 'string', 'children': [], 'value': "'sortby'"},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '106', 'type': 'string', 'children': [], 'value': '"the sorting criteria (\'from\' or \'to\')"'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'return_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '121']},{'id': '117', 'type': 'attribute', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'KnwKBMappingsResource'},{'id': '119', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'search_mappings'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123', '126', '129', '132', '135', '138']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'kb'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '125', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '128', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '131', 'type': 'string', 'children': [], 'value': "'match_type'"},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '134', 'type': 'string', 'children': [], 'value': "'sortby'"},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '137', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '140', 'type': 'string', 'children': [], 'value': "'per_page'"}
def get(self, slug): kb = api.get_kb_by_slug(slug) check_knowledge_access(kb) parser = reqparse.RequestParser() parser.add_argument( 'from', type=str, help="Return only entries where 'from' matches this.") parser.add_argument( 'to', type=str, help="Return only entries where 'to' matches this.") parser.add_argument('page', type=int, help="Require a specific page") parser.add_argument('per_page', type=int, help="Set how much result per page") parser.add_argument('match_type', type=str, help="s=substring, e=exact, sw=startswith") parser.add_argument('sortby', type=str, help="the sorting criteria ('from' or 'to')") args = parser.parse_args() return KnwKBMappingsResource \ .search_mappings(kb, args['from'], args['to'], args['match_type'], args['sortby'], args['page'], args['per_page'])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pretty'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14', '95']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': '"sort values and format output for viewing and comparing in test scenarios"'},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '27']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '39', '58', '71', '84']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'elif_clause', 'children': ['40', '44']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'is_str_or_unicode'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'elif_clause', 'children': ['59', '64']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'elif_clause', 'children': ['72', '77']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '83', 'type': 'dictionary', 'children': []},{'id': '84', 'type': 'else_clause', 'children': ['85']},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'unicode_value'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pretty_obj'}
def pretty(self): "sort values and format output for viewing and comparing in test scenarios" pretty_obj = OrderedDict() for key, value in sorted(iteritems(self.__dict__)): if value is None: pretty_obj[key] = None elif is_str_or_unicode(value): pretty_obj[key] = self.__dict__.get(key) elif isinstance(value, list): pretty_obj[key] = [] elif isinstance(value, dict): pretty_obj[key] = {} else: pretty_obj[key] = unicode_value(value) return pretty_obj
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_directory'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '12']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'module_basename'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '20', '28', '36', '78', '87']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'''Load all python modules in directory and directory's children.\n Parameters\n ----------\n :``module_basename``: module name prefix for loaded modules\n :``directory``: directory to load python modules from\n :``sort_key``: function to sort module names with before loading\n '''"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'loading submodules of %s'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'module_basename'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'loading modules from %s'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'list_splat', 'children': ['45']},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '63', '71']},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '58']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '62', 'type': 'integer', 'children': [], 'value': '2'},{'id': '63', 'type': 'for_in_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '71', 'type': 'if_clause', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '77', 'type': 'integer', 'children': [], 'value': '2'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'modulenames'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_filenames_to_modulenames'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'module_basename'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '96']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'modulename'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'modulenames'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'try_statement', 'children': ['98', '106', '124']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'importlib'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'modulename'},{'id': '106', 'type': 'except_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '108', 'type': 'block', 'children': ['109', '117']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "'failed loading %s'"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'modulename'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'module loading failure'"},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'successfully loaded %s'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'modulename'}
def import_directory(module_basename: str, directory: str, sort_key = None) -> None: '''Load all python modules in directory and directory's children. Parameters ---------- :``module_basename``: module name prefix for loaded modules :``directory``: directory to load python modules from :``sort_key``: function to sort module names with before loading ''' logger.info('loading submodules of %s', module_basename) logger.info('loading modules from %s', directory) filenames = itertools.chain(*[ [ os.path.join(_[0], filename) for filename in _[2] ] for _ in os.walk(directory) if len(_[2]) ]) modulenames = _filenames_to_modulenames(filenames, module_basename, directory) for modulename in sorted(modulenames, key = sort_key): try: importlib.import_module(modulename) except ImportError: logger.warning('failed loading %s', modulename) logger.exception('module loading failure') else: logger.info('successfully loaded %s', modulename)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'given_file'},{'id': '6', 'type': 'block', 'children': ['7', '25', '36', '50', '108', '119', '136']},{'id': '7', 'type': 'if_statement', 'children': ['8', '19']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'and'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"Attribute \'unique\' is not True or False."'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'given_file'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'Read-only opening {0}'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'},{'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': 'filename'},{'id': '50', 'type': 'with_statement', 'children': ['51', '63']},{'id': '51', 'type': 'with_clause', 'children': ['52']},{'id': '52', 'type': 'with_item', 'children': ['53']},{'id': '53', 'type': 'as_pattern', 'children': ['54', '61']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '60', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '67', 'type': 'block', 'children': ['68', '77', '86']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'\\r\\n'"},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '80', 'type': 'None', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'string', 'children': [], 'value': "''"},{'id': '86', 'type': 'if_statement', 'children': ['87', '98']},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '93'], 'value': 'or'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': 'is'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '92', 'type': 'False', 'children': []},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '108', 'type': 'if_statement', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'Read {0} lines.'"},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'True', 'children': []}
def read(self, given_file): if self.unique is not False and self.unique is not True: raise AttributeError("Attribute 'unique' is not True or False.") self.filename = str.strip(given_file) self.log('Read-only opening {0}'.format(self.filename)) with open(self.filename, 'r') as handle: for line in handle: line = line.rstrip('\r\n') if line is None: line = '' if self.unique is False or line not in self.contents: self.contents.append(line) if self.sorted: self.sort() self.log('Read {0} lines.'.format(len(self.contents))) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'force_clear_lock'},{'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': "'''Kick out whoever currently owns the namespace global lock.\n This is intended as purely a last-resort tool. If another\n process has managed to get the global lock for a very long time,\n or if it requested the lock with a long expiration and then\n crashed, this can make the system functional again. If the\n original lock holder is still alive, its session calls may fail\n with exceptions.\n '''"},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '22']},{'id': '10', 'type': 'attribute', 'children': ['11', '21']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'redis'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Redis'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'connection_pool'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_lock_name'}
def force_clear_lock(self): '''Kick out whoever currently owns the namespace global lock. This is intended as purely a last-resort tool. If another process has managed to get the global lock for a very long time, or if it requested the lock with a long expiration and then crashed, this can make the system functional again. If the original lock holder is still alive, its session calls may fail with exceptions. ''' return redis.Redis(connection_pool=self.pool).delete(self._lock_name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prettyprint'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '9', 'type': 'argument_list', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16', '19', '22']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '21', 'type': 'integer', 'children': [], 'value': '4'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'separators'},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': '","'},{'id': '26', 'type': 'string', 'children': [], 'value': '": "'}
def prettyprint(d): print(json.dumps(d, sort_keys=True, indent=4, separators=("," , ": ")))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_iterable'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'try_statement', 'children': ['7', '13', '20']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '13', 'type': 'except_clause', 'children': ['14', '17']},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'else_clause', 'children': ['21']},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'basestring'}
def _is_iterable(val): try: iter(val) except (ValueError, TypeError): return False else: return not isinstance(val, basestring)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'square_off'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'transition_seconds'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'block', 'children': ['12', '94']},{'id': '12', 'type': 'if_statement', 'children': ['13', '14', '42']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '14', 'type': 'block', 'children': ['15', '34']},{'id': '15', 'type': 'if_statement', 'children': ['16', '23']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '20', 'type': 'tuple', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'float'},{'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': 'time_delta'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'new_times'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '41'], 'value': '+'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '42', 'type': 'else_clause', 'children': ['43']},{'id': '43', 'type': 'block', 'children': ['44', '55', '69', '77']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'diff'},{'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': 'diff'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'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': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[diff[-1]]'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '67', 'type': 'unary_operator', 'children': ['68'], 'value': '-'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_times'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '76'], 'value': '+'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'time_delta'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'new_times'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '87'], 'value': '-'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'DatetimeIndex'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'new_times'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'transition_seconds'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '116']},{'id': '96', 'type': 'attribute', 'children': ['97', '115']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'list', 'children': ['103', '104'], 'value': '[series, pd.Series(series.values, index=new_times)]'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '108', 'type': 'argument_list', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'new_times'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '116', 'type': 'argument_list', 'children': []}
def square_off(series, time_delta=None, transition_seconds=1): if time_delta: if isinstance(time_delta, (int, float)): time_delta = datetime.timedelta(0, time_delta) new_times = series.index + time_delta else: diff = np.diff(series.index) time_delta = np.append(diff, [diff[-1]]) new_times = series.index + time_delta new_times = pd.DatetimeIndex(new_times) - datetime.timedelta(0, transition_seconds) return pd.concat([series, pd.Series(series.values, index=new_times)]).sort_index()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortframe'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14', '32', '38', '44']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n sorts particles for a frame\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '13', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sortedargs'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'lexsort'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'list', 'children': ['23', '26', '29'], 'value': "[d['xi'],d['yi'],d['zi']]"},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '25', 'type': 'string', 'children': [], 'value': "'xi'"},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '28', 'type': 'string', 'children': [], 'value': "'yi'"},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '31', 'type': 'string', 'children': [], 'value': "'zi'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sortedargs'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'frame'},{'id': '42', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'frame'}
def sortframe(frame): ''' sorts particles for a frame ''' d = frame['data']; sortedargs = np.lexsort([d['xi'],d['yi'],d['zi']]) d = d[sortedargs]; frame['data']=d; return frame;
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_release_id'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '21', '28']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '11', 'type': 'call', 'children': ['12', '19']},{'id': '12', 'type': 'attribute', 'children': ['13', '18']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'utcnow'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'RELEASE_DATE_FMT'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'{0}-{1}'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'version'}
def get_release_id(version=None): ts = datetime.utcnow().strftime(RELEASE_DATE_FMT) if version is None: return ts return '{0}-{1}'.format(ts, version)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_objects_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'valueLabel'},{'id': '9', 'type': 'string', 'children': [], 'value': '"value"'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'childrenLabel'},{'id': '12', 'type': 'string', 'children': [], 'value': '"children"'},{'id': '13', 'type': 'block', 'children': ['14', '18', '104']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '21', 'type': 'block', 'children': ['22', '31', '36', '50', '54', '93']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '31', 'type': 'if_statement', 'children': ['32', '34']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'pass_statement', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'newGroup'},{'id': '39', 'type': 'dictionary', 'children': ['40', '43', '46']},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '"attribute"'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'valueLabel'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'childrenLabel'},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '[obj]'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '64']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '76']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'valueLabel'},{'id': '76', 'type': 'block', 'children': ['77', '81', '92']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '80', 'type': 'True', 'children': []},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '90']},{'id': '83', 'type': 'attribute', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'childrenLabel'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '92', 'type': 'pass_statement', 'children': []},{'id': '93', 'type': 'if_statement', 'children': ['94', '96']},{'id': '94', 'type': 'not_operator', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'newGroup'},{'id': '104', 'type': 'return_statement', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'groups'}
def group_objects_by(self, list, attr, valueLabel="value", childrenLabel="children"): groups = [] for obj in list: val = obj.get(attr) if not val: pass newGroup = {"attribute": attr, valueLabel: val, childrenLabel: [obj]} found = False for i in range(0,len(groups)): if val == groups[i].get(valueLabel): found = True groups[i][childrenLabel].append(obj) pass if not found: groups.append(newGroup) return groups
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorts_query'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sortables'},{'id': '5', 'type': 'block', 'children': ['6', '10', '49']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'stmts'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sortable'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sortables'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18', '33']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sortable'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'desc'},{'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': 'stmts'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'{} DESC'"},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sortable'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'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': 'stmts'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'{} ASC'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sortable'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "' ORDER BY {}'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "', '"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'stmts'}
def sorts_query(sortables): stmts = [] for sortable in sortables: if sortable.desc: stmts.append('{} DESC'.format(sortable.field)) else: stmts.append('{} ASC'.format(sortable.field)) return ' ORDER BY {}'.format(', '.join(stmts))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '16', '20', '34', '57', '78', '88', '99', '117', '128', '148', '152', '156', '160', '174', '186', '197', '214', '223', '238']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'rtype_to_model'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pages'},{'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': 'pages_query'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'string', 'children': [], 'value': "'pages'"},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorts'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorts_query'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'sorts'"},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '[Sortable(goldman.config.SORT)]'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'Sortable'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'goldman'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'SORT'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '66', 'type': 'argument_list', 'children': ['67', '75']},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'field_cols'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'rtype'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'filters'"},{'id': '87', 'type': 'list', 'children': [], 'value': '[]'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '91', 'type': 'boolean_operator', 'children': ['92', '98'], 'value': 'or'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '96', 'type': 'string', 'children': [], 'value': "'search_filters'"},{'id': '97', 'type': 'list', 'children': [], 'value': '[]'},{'id': '98', 'type': 'list', 'children': [], 'value': '[]'},{'id': '99', 'type': 'if_statement', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '101', 'type': 'block', 'children': ['102', '113']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '107']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'filters_query'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'augmented_assignment', 'children': ['115', '116'], 'value': '+='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '127'], 'value': 'or'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '125', 'type': 'string', 'children': [], 'value': "'search_query'"},{'id': '126', 'type': 'string', 'children': [], 'value': "''"},{'id': '127', 'type': 'string', 'children': [], 'value': "''"},{'id': '128', 'type': 'if_statement', 'children': ['129', '132', '139']},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '131'], 'value': 'and'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '+'},{'id': '137', 'type': 'string', 'children': [], 'value': "' AND '"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '139', 'type': 'elif_clause', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'string', 'children': [], 'value': "' WHERE '"},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'augmented_assignment', 'children': ['150', '151'], 'value': '+='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'model_query'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '+='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sorts'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'augmented_assignment', 'children': ['158', '159'], 'value': '+='},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'pages'},{'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': 'signals'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'pre_search'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '167', 'type': 'argument_list', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '189', 'type': 'list_comprehension', 'children': ['190', '194']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '197', 'type': 'if_statement', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'signals'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'post_search'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '207', 'type': 'argument_list', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': "'pages'"},{'id': '223', 'type': 'if_statement', 'children': ['224', '227']},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '226'], 'value': 'and'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'pages'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '233', 'type': 'subscript', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'string', 'children': [], 'value': "'_count'"},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'models'}
def search(self, rtype, **kwargs): model = rtype_to_model(rtype) param = {} pages = self.pages_query(kwargs.get('pages')) sorts = self.sorts_query(kwargs.get( 'sorts', [Sortable(goldman.config.SORT)] )) query = query = query.format( cols=self.field_cols(model), table=rtype, ) filters = kwargs.get('filters', []) filters += getattr(model, 'search_filters', []) or [] if filters: where, param = self.filters_query(filters) query += where model_query = getattr(model, 'search_query', '') or '' if filters and model_query: model_query = ' AND ' + model_query elif model_query: model_query = ' WHERE ' + model_query query += model_query query += sorts query += pages signals.pre_search.send(model.__class__, model=model) result = self.query(query, param=param) models = [model(res) for res in result] if models: signals.post_search.send(model.__class__, models=result) pages = kwargs.get('pages') if pages and result: pages.total = result[0]['_count'] return models
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'force_seek'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'chunk'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'CHUNK'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'try_statement', 'children': ['11', '19']},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '19', 'type': 'except_clause', 'children': ['20', '25']},{'id': '20', 'type': 'tuple', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'UnsupportedOperation'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'emulate_seek'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'fd'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'chunk'}
def force_seek(fd, offset, chunk=CHUNK): try: fd.seek(offset) except (AttributeError, io.UnsupportedOperation): emulate_seek(fd, offset, chunk)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'append'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'hcont'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '25', '44']},{'id': '11', 'type': 'assert_statement', 'children': ['12']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '17'], 'value': '!='},{'id': '13', 'type': '()', 'children': ['14']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': '()', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '24'], 'value': 'is'},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'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': 'score'},{'id': '28', 'type': 'None', 'children': []},{'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': 'score'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'attribute', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort_field'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'ContainerFieldWriter'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'hcont'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'score'}
def append(self, hcont, value, score = None): assert (score is None) != (self.field.sort_field is None) if score is None: score = getattr(value, self.field.sort_field.name) ContainerFieldWriter.append(self, hcont, value, score)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'raise_errors_on_nested_writes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'validated_data'},{'id': '7', 'type': 'block', 'children': ['8', '71']},{'id': '8', 'type': 'assert_statement', 'children': ['9', '44']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '12', 'type': 'generator_expression', 'children': ['13', '33']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '24'], 'value': 'and'},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '20'], 'value': 'and'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'BaseSerializer'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'validated_data'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'validated_data'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'tuple', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '37']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': '()', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'concatenated_string', 'children': ['48', '49', '50', '51']},{'id': '48', 'type': 'string', 'children': [], 'value': "'The `.{method_name}()` method does not support writable nested'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'fields by default.\\nWrite an explicit `.{method_name}()` method for '"},{'id': '50', 'type': 'string', 'children': [], 'value': "'serializer `{module}.{class_name}`, or set `read_only=True` on '"},{'id': '51', 'type': 'string', 'children': [], 'value': "'nested serializer fields.'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57', '64']},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '71', 'type': 'assert_statement', 'children': ['72', '107']},{'id': '72', 'type': 'not_operator', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '75', 'type': 'generator_expression', 'children': ['76', '96']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '87'], 'value': 'and'},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '83'], 'value': 'and'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'validated_data'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'validated_data'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'tuple', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '100']},{'id': '97', 'type': 'pattern_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '100', 'type': 'call', 'children': ['101', '106']},{'id': '101', 'type': 'attribute', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': '()', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '116']},{'id': '109', 'type': 'attribute', 'children': ['110', '115']},{'id': '110', 'type': 'concatenated_string', 'children': ['111', '112', '113', '114']},{'id': '111', 'type': 'string', 'children': [], 'value': "'The `.{method_name}()` method does not support writable dotted-source '"},{'id': '112', 'type': 'string', 'children': [], 'value': "'fields by default.\\nWrite an explicit `.{method_name}()` method for '"},{'id': '113', 'type': 'string', 'children': [], 'value': "'serializer `{module}.{class_name}`, or set `read_only=True` on '"},{'id': '114', 'type': 'string', 'children': [], 'value': "'dotted-source serializer fields.'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120', '127']},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'method_name'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'class_name'},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'serializer'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '__name__'}
def raise_errors_on_nested_writes(method_name, serializer, validated_data): assert not any( isinstance(field, BaseSerializer) and (key in validated_data) and isinstance(validated_data[key], (list, dict)) for key, field in serializer.fields.items() ), ( 'The `.{method_name}()` method does not support writable nested' 'fields by default.\nWrite an explicit `.{method_name}()` method for ' 'serializer `{module}.{class_name}`, or set `read_only=True` on ' 'nested serializer fields.'.format( method_name=method_name, module=serializer.__class__.__module__, class_name=serializer.__class__.__name__ ) ) assert not any( '.' in field.source and (key in validated_data) and isinstance(validated_data[key], (list, dict)) for key, field in serializer.fields.items() ), ( 'The `.{method_name}()` method does not support writable dotted-source ' 'fields by default.\nWrite an explicit `.{method_name}()` method for ' 'serializer `{module}.{class_name}`, or set `read_only=True` on ' 'dotted-source serializer fields.'.format( method_name=method_name, module=serializer.__class__.__module__, class_name=serializer.__class__.__name__ ) )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'threenum'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'h5file'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'post_col'},{'id': '8', 'type': 'string', 'children': [], 'value': "'mult'"},{'id': '9', 'type': 'block', 'children': ['10', '20', '26', '32', '40', '48', '60', '71', '75', '79', '205', '211', '220']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'h5py'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'File'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'h5file'},{'id': '19', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'post_col'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'wsum'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '87']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86']},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '87', 'type': 'block', 'children': ['88', '123', '136', '149', '158', '167', '176', '185', '196']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'aN'},{'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '~'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'logical_or'},{'id': '96', 'type': 'argument_list', 'children': ['97', '110']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '104', 'type': 'slice', 'children': ['105', '106', '107']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'colon', 'children': []},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'isinf'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '117', 'type': 'slice', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'd_c'},{'id': '126', 'type': 'subscript', 'children': ['127', '135']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '129', 'type': 'slice', 'children': ['130', '131', '132']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'colon', 'children': []},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'aN'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'w_c'},{'id': '139', 'type': 'subscript', 'children': ['140', '148']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '142', 'type': 'slice', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '144', 'type': 'colon', 'children': []},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'aN'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'chunk_max'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'd_c'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'chunk_min'},{'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': 'min'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'd_c'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '170', 'type': 'conditional_expression', 'children': ['171', '172', '175'], 'value': 'if'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'chunk_max'},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '>'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'chunk_max'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '179', 'type': 'conditional_expression', 'children': ['180', '181', '184'], 'value': 'if'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'chunk_min'},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '<'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'chunk_min'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'augmented_assignment', 'children': ['187', '188'], 'value': '+='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '*'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'w_c'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'd_c'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '+='},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'wsum'},{'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': 'sum'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'w_c'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '/'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'wsum'},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'tuple', 'children': ['222', '223', '224']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'mean'}
def threenum(h5file, var, post_col='mult'): f = h5py.File(h5file, 'r') d = f[var] w = f[post_col] s = d.chunks[0] n = d.shape[0] maxval = -np.abs(d[0]) minval = np.abs(d[0]) total = 0 wsum = 0 for x in range(0, n, s): aN = ~np.logical_or(np.isnan(d[x:x+s]), np.isinf(d[x:x+s])) d_c = d[x:x+s][aN] w_c = w[x:x+s][aN] chunk_max = np.max(d_c) chunk_min = np.min(d_c) maxval = chunk_max if chunk_max > maxval else maxval minval = chunk_min if chunk_min < minval else minval total += np.sum(w_c*d_c) wsum += np.sum(w_c) f.close() mean = total/float(wsum) return (minval, maxval, mean)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter_keys'},{'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': 'content_id'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'subtopic_id'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '126']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''Filter out-of-order labels by key tuple.\n :class:`Label` always sorts by `(cid1,cid2,sid1,sid2)`, but\n for efficient lookups on `cid2` this class also stores in\n order `(cid2,cid1,sid2,sid1)`. Filter out things that are\n in the wrong order. But, if an original query specified\n `content_id` or `subtopic_id`, account for the possibility\n that something might be apparently out-of-order but its\n dual will not be in the query at all.\n '''"},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'accept'},{'id': '19', 'type': 'parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'kvp'},{'id': '21', 'type': 'block', 'children': ['22', '34', '50', '90', '106', '113', '124']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '31']},{'id': '24', 'type': 'tuple_pattern', 'children': ['25', '26', '27', '28', '29', '30']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'content_id1'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'subtopic_id1'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'subtopic_id2'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'annotator_id'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'inverted_epoch_ticks'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kvp'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '<'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'content_id1'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'content_id1'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '<='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'subtopic_id1'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'subtopic_id2'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '59', '84']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'content_id'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'assert_statement', 'children': ['56']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'content_id1'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'content_id'},{'id': '59', 'type': 'elif_clause', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '71']},{'id': '64', 'type': 'assert_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'content_id1'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '71', 'type': 'if_statement', 'children': ['72', '81']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '79'], 'value': 'and'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'False', 'children': []},{'id': '84', 'type': 'elif_clause', 'children': ['85', '87']},{'id': '85', 'type': 'not_operator', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'False', 'children': []},{'id': '90', 'type': 'if_statement', 'children': ['91', '94']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'subtopic_id'},{'id': '93', 'type': 'None', 'children': []},{'id': '94', 'type': 'block', 'children': ['95', '102']},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '!='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'content_id'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'True', 'children': []},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '<='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'subtopic_id1'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'subtopic_id2'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '=='},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'subtopic_id'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'subtopic_id1'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'True', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '121']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '118'], 'value': 'and'},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'content_id'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'content_id2'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'subtopic_id'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'subtopic_id2'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'True', 'children': []},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'False', 'children': []},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'accept'}
def _filter_keys(self, content_id=None, prefix=None, subtopic_id=None): '''Filter out-of-order labels by key tuple. :class:`Label` always sorts by `(cid1,cid2,sid1,sid2)`, but for efficient lookups on `cid2` this class also stores in order `(cid2,cid1,sid2,sid1)`. Filter out things that are in the wrong order. But, if an original query specified `content_id` or `subtopic_id`, account for the possibility that something might be apparently out-of-order but its dual will not be in the query at all. ''' def accept(kvp): (content_id1, content_id2, subtopic_id1, subtopic_id2, annotator_id, inverted_epoch_ticks) = kvp[0] is_sorted = (content_id1 < content_id2 or (content_id1 == content_id2 and subtopic_id1 <= subtopic_id2)) if content_id is not None: assert content_id1 == content_id elif prefix is not None: assert content_id1.startswith(prefix) if content_id2.startswith(prefix) and not is_sorted: return False elif not is_sorted: return False if subtopic_id is None: if content_id2 != content_id: return True return subtopic_id1 <= subtopic_id2 if subtopic_id == subtopic_id1: return True if content_id == content_id2 and subtopic_id == subtopic_id2: return True return False return accept
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_sorting'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '6', 'type': 'block', 'children': ['7', '9', '13', '25', '32', '39', '47', '110', '135']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''An implementation of Kahn's algorithm.\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '21'], 'value': '|'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_nodes'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'inc'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_incoming'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_outgoing'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'relations'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'free'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_free_nodes'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'inc'},{'id': '47', 'type': 'while_statement', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'free'},{'id': '49', 'type': 'block', 'children': ['50', '58', '65', '74']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'free'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '57', 'type': 'argument_list', 'children': []},{'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': 'ret'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'out_n'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'out_n'},{'id': '77', 'type': 'block', 'children': ['78', '87', '96']},{'id': '78', 'type': 'expression_statement', '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': 'out'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'inc'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_is_free'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'inc'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'free'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '110', 'type': 'if_statement', 'children': ['111', '129']},{'id': '111', 'type': 'not_operator', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '114', 'type': 'generator_expression', 'children': ['115', '126']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '121'], 'value': 'and'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_is_free'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'inc'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_is_free'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'raise_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'string', 'children': [], 'value': '"Cycle detected"'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ret'}
def topological_sorting(nodes, relations): '''An implementation of Kahn's algorithm. ''' ret = [] nodes = set(nodes) | _nodes(relations) inc = _incoming(relations) out = _outgoing(relations) free = _free_nodes(nodes, inc) while free: n = free.pop() ret.append(n) out_n = list(out[n]) for m in out_n: out[n].remove(m) inc[m].remove(n) if _is_free(m, inc): free.add(m) if not all(_is_free(node, inc) and _is_free(node, out) for node in nodes): raise ValueError("Cycle detected") return ret
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'solve_resource'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '7', 'type': 'block', 'children': ['8', '31']},{'id': '8', 'type': 'for_statement', 'children': ['9', '10', '16']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'solver'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'get_resource_solvers'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'try_statement', 'children': ['18', '27']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'solver'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'solve'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '27', 'type': 'except_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'CannotSolve'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'continue_statement', 'children': []},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'SolveFailure'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}
def solve_resource(self, value, resource): for solver in self.get_resource_solvers(resource): try: return solver.solve(value, resource) except CannotSolve: continue raise SolveFailure(self, resource, value)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'incrementName'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nameList'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'block', 'children': ['7', '14', '23', '67']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'not'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nameList'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'newName'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '+'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '35']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '34'], 'value': '+'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nameList'},{'id': '34', 'type': 'integer', 'children': [], 'value': '2'},{'id': '35', 'type': 'block', 'children': ['36', '40', '62']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '39', 'type': 'False', 'children': []},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'nameList'},{'id': '43', 'type': 'block', 'children': ['44', '53']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'newName'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '=='},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'newName'},{'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': 'found'},{'id': '61', 'type': 'True', 'children': []},{'id': '62', 'type': 'if_statement', 'children': ['63', '65']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'break_statement', 'children': []},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'newName'}
def incrementName(nameList, name): if name not in nameList: return name newName = name + str(1) for n in range(1, len(nameList) + 2): found = False for b in nameList: newName = name + str(n) if b == newName: found = True if not found: break return newName
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'polylines'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'for_statement', 'children': ['7', '10', '14']},{'id': '7', 'type': 'pattern_list', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'polylines'},{'id': '14', 'type': 'block', 'children': ['15', '22']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '>'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '25', 'type': 'integer', 'children': [], 'value': '2'},{'id': '26', 'type': 'block', 'children': ['27', '38', '45', '56', '65', '76', '112', '119', '128', '137', '143']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'distV'},{'id': '41', 'type': '()', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '-'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'distV'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'firstI'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sign'},{'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': 'sign'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'distV'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'firstI'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dd'},{'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': 'logical_or'},{'id': '83', 'type': 'argument_list', 'children': ['84', '98']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '95'], 'value': '!='},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'subscript', 'children': ['91', '92', '94']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'distV'},{'id': '92', 'type': 'slice', 'children': ['93']},{'id': '93', 'type': 'colon', 'children': []},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '109'], 'value': '!='},{'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': 'sign'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'subscript', 'children': ['105', '106', '108']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'distV'},{'id': '106', 'type': 'slice', 'children': ['107']},{'id': '107', 'type': 'colon', 'children': []},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '118']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '116', 'type': 'unary_operator', 'children': ['117'], 'value': '~'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'dd'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'lastI'},{'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': 'argmax'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dists'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_sort'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'firstI'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lastI'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'polylines'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'c'}
def sort(polylines): for n, c in enumerate(polylines): l = len(c) if l > 2: mid = c.mean(axis=0) distV = (c - mid) dists = norm(distV, axis=-1) firstI = np.argmax(dists) sign = np.sign(distV[firstI]) dd = np.logical_or(np.sign(distV[:, 0]) != sign[0], np.sign(distV[:, 1]) != sign[1]) dists[~dd] = 0 lastI = np.argmax(dists) ind = _sort(c, firstI, lastI) c = c[ind] polylines[n] = c
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_queryset'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '34']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '9', 'type': 'call', 'children': ['10', '17']},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'MostVotedManager'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_queryset'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'queryset'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '30', 'type': 'dictionary', 'children': ['31']},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'vote_count'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sql'},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'-vote_count'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'received_time'"}
def get_queryset(self): queryset = super(MostVotedManager, self).get_queryset() sql = messages = queryset.extra( select={ 'vote_count': sql, } ) return messages.order_by('-vote_count', 'received_time')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'deleteByOrigIndex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '53', '59', '65']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'result_tracker'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'for_statement', 'children': ['16', '19', '25']},{'id': '16', 'type': 'pattern_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '34']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '33'], 'value': '!='},{'id': '28', 'type': 'subscript', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '34', 'type': 'block', 'children': ['35', '42']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'result_tracker'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'subscript', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result_tracker'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}
def deleteByOrigIndex(self, index): result = [] result_tracker = [] for counter, row in enumerate(self.table): if self.index_track[counter] != index: result.append(row) result_tracker.append(self.index_track[counter]) self.table = result self.index_track = result_tracker return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'deleteByOrigIndexList'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indexList'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '53', '59', '65']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'result_tracker'},{'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': 'counter'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '24', 'type': 'block', 'children': ['25', '49']},{'id': '25', 'type': 'if_statement', 'children': ['26', '30']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'indexList'},{'id': '30', 'type': 'block', 'children': ['31', '38']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'row'},{'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': 'result_tracker'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'counter'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result_tracker'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}
def deleteByOrigIndexList(self, indexList): result = [] result_tracker = [] counter = 0 for row in self.table: if not counter in indexList: result.append(row) result_tracker.append(self.index_track[counter]) counter += 1 self.table = result self.index_track = result_tracker return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'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': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'none_greater'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '15', '128']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': '\'\'\'Sort the list in the order of the dictionary key.\n Example of use:\n >>> test = [\n ... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 },\n ... {"name": "Larry", "age": 18, "wigs": [3, 2, 9]},\n ... {"name": "Joe", "age": 20, "income": 15000, "wigs": [1, 2, 3]},\n ... {"name": "Bill", "age": 19, "income": 29000 },\n ... ]\n >>> print PLOD(test).sort("name").returnString()\n [\n {age: 19, income: 29000, name: \'Bill\' , wigs: None },\n {age: 18, income: 93000, name: \'Jim\' , wigs: 68},\n {age: 20, income: 15000, name: \'Joe\' , wigs: [1, 2, 3]},\n {age: 18, income: None , name: \'Larry\', wigs: [3, 2, 9]}\n ]\n >>> print PLOD(test).sort("income").returnString()\n [\n {age: 18, income: None , name: \'Larry\', wigs: [3, 2, 9]},\n {age: 20, income: 15000, name: \'Joe\' , wigs: [1, 2, 3]},\n {age: 19, income: 29000, name: \'Bill\' , wigs: None },\n {age: 18, income: 93000, name: \'Jim\' , wigs: 68}\n ]\n >>> print PLOD(test).sort(["age", "income"]).returnString()\n [\n {age: 18, income: None , name: \'Larry\', wigs: [3, 2, 9]},\n {age: 18, income: 93000, name: \'Jim\' , wigs: 68},\n {age: 19, income: 29000, name: \'Bill\' , wigs: None },\n {age: 20, income: 15000, name: \'Joe\' , wigs: [1, 2, 3]}\n ]\n .. versionadded:: 0.0.2\n :param key:\n A dictionary key (or a list of keys) that should be the\n basis of the sorting.\n :param reverse:\n Defaults to False. If True, then list is sorted decrementally.\n :param none_greater:\n Defaults to False. If True, then entries missing the key/value\n pair are considered be of greater value than the non-missing values.\n :returns: self\n \'\'\''},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '27']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '27', 'type': 'block', 'children': ['28', '32', '75']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '46']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '+'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'integer', 'children': [], 'value': '1'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'if_statement', 'children': ['48', '70']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'internal'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'is_first_lessor'},{'id': '52', 'type': 'argument_list', 'children': ['53', '58', '63', '64', '67']},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '58', 'type': 'subscript', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'none_greater'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'none_greater'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '!='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '79', 'type': 'block', 'children': ['80', '104']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '93']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '88']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '93', 'type': 'expression_list', 'children': ['94', '99']},{'id': '94', 'type': 'subscript', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '99', 'type': 'subscript', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '117']},{'id': '106', 'type': 'pattern_list', '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': 'index_track'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '117', 'type': 'expression_list', 'children': ['118', '123']},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'return_statement', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, key, reverse=False, none_greater=False): '''Sort the list in the order of the dictionary key. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 }, ... {"name": "Larry", "age": 18, "wigs": [3, 2, 9]}, ... {"name": "Joe", "age": 20, "income": 15000, "wigs": [1, 2, 3]}, ... {"name": "Bill", "age": 19, "income": 29000 }, ... ] >>> print PLOD(test).sort("name").returnString() [ {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]} ] >>> print PLOD(test).sort("income").returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 18, income: 93000, name: 'Jim' , wigs: 68} ] >>> print PLOD(test).sort(["age", "income"]).returnString() [ {age: 18, income: None , name: 'Larry', wigs: [3, 2, 9]}, {age: 18, income: 93000, name: 'Jim' , wigs: 68}, {age: 19, income: 29000, name: 'Bill' , wigs: None }, {age: 20, income: 15000, name: 'Joe' , wigs: [1, 2, 3]} ] .. versionadded:: 0.0.2 :param key: A dictionary key (or a list of keys) that should be the basis of the sorting. :param reverse: Defaults to False. If True, then list is sorted decrementally. :param none_greater: Defaults to False. If True, then entries missing the key/value pair are considered be of greater value than the non-missing values. :returns: self ''' for i in range(0, len(self.table)): min = i for j in range(i + 1, len(self.table)): if internal.is_first_lessor(self.table[j], self.table[min], key, none_greater=none_greater, reverse=reverse): min = j if i!=min: self.table[i], self.table[min] = self.table[min], self.table[i] self.index_track[i], self.index_track[min] = self.index_track[min], self.index_track[i] return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'returnIndexList'},{'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': 'limit'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '20', '24', '52']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'Return a list of integers that are list-index references to the\n original list of dictionaries."\n Example of use:\n >>> test = [\n ... {"name": "Jim", "age": 18, "income": 93000, "order": 2},\n ... {"name": "Larry", "age": 18, "order": 3},\n ... {"name": "Joe", "age": 20, "income": 15000, "order": 1},\n ... {"name": "Bill", "age": 19, "income": 29000, "order": 4},\n ... ]\n >>> print PLOD(test).returnIndexList()\n [0, 1, 2, 3]\n >>> print PLOD(test).sort("name").returnIndexList()\n [3, 0, 2, 1]\n :param limit:\n A number limiting the quantity of entries to return. Defaults to\n False, which means that the full list is returned.\n :return:\n A list of integers representing the original indices.\n \'\'\''},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '=='},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '30']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'if_statement', 'children': ['32', '40']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '39'], 'value': '>'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'result'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'subscript', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'index_track'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'result'}
def returnIndexList(self, limit=False): '''Return a list of integers that are list-index references to the original list of dictionaries." Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnIndexList() [0, 1, 2, 3] >>> print PLOD(test).sort("name").returnIndexList() [3, 0, 2, 1] :param limit: A number limiting the quantity of entries to return. Defaults to False, which means that the full list is returned. :return: A list of integers representing the original indices. ''' if limit==False: return self.index_track result = [] for i in range(limit): if len(self.table)>i: result.append(self.index_track[i]) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'returnValue'},{'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': 'last'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '23', '29', '38']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '\'\'\'Return the key\'s value for the first entry in the current list.\n If \'last=True\', then the last entry is referenced."\n Returns None is the list is empty or the key is missing.\n Example of use:\n >>> test = [\n ... {"name": "Jim", "age": 18, "income": 93000, "order": 2},\n ... {"name": "Larry", "age": 18, "order": 3},\n ... {"name": "Joe", "age": 20, "income": 15000, "order": 1},\n ... {"name": "Bill", "age": 19, "income": 29000, "order": 4},\n ... ]\n >>> print PLOD(test).returnValue("name")\n Jim\n >>> print PLOD(test).sort("name").returnValue("name", last=True)\n Larry\n >>> print PLOD(test).sort("name").returnValue("income", last=True)\n None\n :param last:\n If True, the last entry is used rather than the first.\n :return:\n A value, or None if the list is empty or the key is missing.\n \'\'\''},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'returnOneEntry'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '23', 'type': 'if_statement', 'children': ['24', '26']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict_row'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'internal'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'convert_to_dict'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dict_row'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'None', 'children': []}
def returnValue(self, key, last=False): '''Return the key's value for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty or the key is missing. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValue("name") Jim >>> print PLOD(test).sort("name").returnValue("name", last=True) Larry >>> print PLOD(test).sort("name").returnValue("income", last=True) None :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty or the key is missing. ''' row = self.returnOneEntry(last=last) if not row: return None dict_row = internal.convert_to_dict(row) return dict_row.get(key, None)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'returnValueList'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_list'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '12', '16', '27', '33', '42', '59']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '\'\'\'Return a list of key values for the first entry in the current list.\n If \'last=True\', then the last entry is referenced."\n Returns None is the list is empty. If a key is missing, then\n that entry in the list is None.\n Example of use:\n >>> test = [\n ... {"name": "Jim", "age": 18, "income": 93000, "order": 2},\n ... {"name": "Larry", "age": 18, "order": 3},\n ... {"name": "Joe", "age": 20, "income": 15000, "order": 1},\n ... {"name": "Bill", "age": 19, "income": 29000, "order": 4},\n ... ]\n >>> print PLOD(test).returnValueList(["name", "income"])\n [\'Jim\', 93000]\n >>> print PLOD(test).sort("name").returnValueList(["name", "income"], last=True)\n [\'Larry\', None]\n :param last:\n If True, the last entry is used rather than the first.\n :return:\n A value, or None if the list is empty.\n \'\'\''},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'returnOneEntry'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '27', 'type': 'if_statement', 'children': ['28', '30']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'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': 'dict_row'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'internal'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'convert_to_dict'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key_list'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dict_row'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'result'}
def returnValueList(self, key_list, last=False): '''Return a list of key values for the first entry in the current list. If 'last=True', then the last entry is referenced." Returns None is the list is empty. If a key is missing, then that entry in the list is None. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "order": 2}, ... {"name": "Larry", "age": 18, "order": 3}, ... {"name": "Joe", "age": 20, "income": 15000, "order": 1}, ... {"name": "Bill", "age": 19, "income": 29000, "order": 4}, ... ] >>> print PLOD(test).returnValueList(["name", "income"]) ['Jim', 93000] >>> print PLOD(test).sort("name").returnValueList(["name", "income"], last=True) ['Larry', None] :param last: If True, the last entry is used rather than the first. :return: A value, or None if the list is empty. ''' result = [] row = self.returnOneEntry(last=last) if not row: return None dict_row = internal.convert_to_dict(row) for field in key_list: result.append(dict_row.get(field, None)) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_seq_records'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'seq_records'},{'id': '6', 'type': 'block', 'children': ['7', '25', '38', '45', '61', '74', '81', '97', '101', '138']},{'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'seq_records'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'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': 'seq_record'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], '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': 'unsorted_gene_codes'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'list_comprehension', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'gene_code'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'seq_records'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted_gene_codes'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'unsorted_gene_codes'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted_gene_codes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'lambda', 'children': ['54', '56']},{'id': '54', 'type': 'lambda_parameters', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'unsorted_voucher_codes'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'list_comprehension', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'seq_records'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted_voucher_codes'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'unsorted_voucher_codes'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted_voucher_codes'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'lambda', 'children': ['90', '92']},{'id': '90', 'type': 'lambda_parameters', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sorted_seq_records'},{'id': '100', 'type': 'list', 'children': [], 'value': '[]'},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'gene_code'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sorted_gene_codes'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sorted_voucher_codes'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'seq_records'},{'id': '112', 'type': 'block', 'children': ['113', '128']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'should_be_done'},{'id': '116', 'type': '()', 'children': ['117']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '123'], 'value': 'and'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': '=='},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'gene_code'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'gene_code'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '=='},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'voucher_code'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'should_be_done'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted_seq_records'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'seq_record'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sorted_seq_records'}
def sort_seq_records(self, seq_records): for seq_record in seq_records: seq_record.voucher_code = seq_record.voucher_code.replace("-", "_") unsorted_gene_codes = set([i.gene_code for i in seq_records]) sorted_gene_codes = list(unsorted_gene_codes) sorted_gene_codes.sort(key=lambda x: x.lower()) unsorted_voucher_codes = set([i.voucher_code for i in seq_records]) sorted_voucher_codes = list(unsorted_voucher_codes) sorted_voucher_codes.sort(key=lambda x: x.lower()) sorted_seq_records = [] for gene_code in sorted_gene_codes: for voucher_code in sorted_voucher_codes: for seq_record in seq_records: should_be_done = ( seq_record.gene_code == gene_code and seq_record.voucher_code == voucher_code ) if should_be_done: sorted_seq_records.append(seq_record) return sorted_seq_records
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'extractFromSQLFile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filePointer'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '8', 'type': 'string', 'children': [], 'value': '";"'},{'id': '9', 'type': 'block', 'children': ['10', '18', '22', '26', '80', '84', '88', '164']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filePointer'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dataLines'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dataLinesIndex'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '29', 'type': 'block', 'children': ['30', '47']},{'id': '30', 'type': 'if_statement', 'children': ['31', '39']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '38'], 'value': '<'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '37'], 'value': '-'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dataLines'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dataLinesIndex'},{'id': '39', 'type': 'block', 'children': ['40']},{'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': 'dataLines'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '""'},{'id': '47', 'type': 'if_statement', 'children': ['48', '59', '64']},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '56'], 'value': 'or'},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'or'},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '=='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '52', 'type': 'string', 'children': [], 'value': '"\\r\\n"'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '55', 'type': 'string', 'children': [], 'value': '"\\r"'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '58', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dataLinesIndex'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'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', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dataLines'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dataLinesIndex'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '"{}{}"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dataLines'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dataLinesIndex'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '83', 'type': 'list', 'children': [], 'value': '[]'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'statementsIndex'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dataLines'},{'id': '91', 'type': 'block', 'children': ['92', '120']},{'id': '92', 'type': 'if_statement', 'children': ['93', '103', '118']},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '100'], 'value': 'or'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': '"--"'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '103', 'type': 'ERROR', 'children': ['104', '106', '107', '112']},{'id': '104', 'type': 'ERROR', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '=='},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'continue_statement', 'children': []},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '123', 'type': 'block', 'children': ['124', '141', '155']},{'id': '124', 'type': 'if_statement', 'children': ['125', '133']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '132'], 'value': '<'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '131'], 'value': '-'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'statementsIndex'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': '""'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'statementsIndex'},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"{}{}"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '150', 'type': 'argument_list', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'statements'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'statementsIndex'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'delimiter'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'augmented_assignment', 'children': ['162', '163'], 'value': '+='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'statementsIndex'},{'id': '163', 'type': 'integer', 'children': [], 'value': '1'},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'statements'}
def extractFromSQLFile(self, filePointer, delimiter=";"): data = filePointer.read() dataLines = [] dataLinesIndex = 0 for c in data: if len(dataLines) - 1 < dataLinesIndex: dataLines.append("") if c == "\r\n" or c == "\r" or c == "\n": dataLinesIndex += 1 else: dataLines[dataLinesIndex] = "{}{}".format( dataLines[dataLinesIndex], c ) statements = [] statementsIndex = 0 for line in dataLines: if line.startswith("--") or line.startswith(" continue line = line.strip() if len(line) == 0: continue for c in line: if len(statements) - 1 < statementsIndex: statements.append("") statements[statementsIndex] = "{}{}".format( statements[statementsIndex], c ) if c == delimiter: statementsIndex += 1 return statements
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '15', '33', '44']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'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': 'lines'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '30']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'k'},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted_data'}
async def sort_data(self, data, sort_key, reverse=False): sorted_data = [] lines = sorted(data, key=lambda k: k[sort_key], reverse=reverse) for line in lines: sorted_data.append(line) return sorted_data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ceiling'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'clouds'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'list', 'children': ['8'], 'value': '[Cloud]'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Cloud'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Cloud'},{'id': '11', 'type': 'block', 'children': ['12', '32']},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'clouds'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '29']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '21'], 'value': 'and'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'altitude'},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'in'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '25', 'type': 'tuple', 'children': ['26', '27', '28']},{'id': '26', 'type': 'string', 'children': [], 'value': "'OVC'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'BKN'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'VV'"},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cloud'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'None', 'children': []}
def get_ceiling(clouds: [Cloud]) -> Cloud: for cloud in clouds: if cloud.altitude and cloud.type in ('OVC', 'BKN', 'VV'): return cloud return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_finish_filter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'include_self'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'exclusive'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'biggest_first'},{'id': '10', 'type': 'block', 'children': ['11', '20', '30', '50', '67', '77', '154', '183']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_actual_key'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'locations'},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '34'], 'value': 'and'},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'include_self'},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'locations'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'locations'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'lst'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '55', 'type': 'argument_list', 'children': ['56', '64']},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'lambda', 'children': ['59', '61']},{'id': '59', 'type': 'lambda_parameters', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'biggest_first'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '70', 'type': 'list_comprehension', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '76']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '77', 'type': 'if_statement', 'children': ['78', '87', '96']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '86'], 'value': 'and'},{'id': '79', 'type': 'boolean_operator', 'children': ['80', '83'], 'value': 'and'},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'not'},{'id': '84', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'exclusive'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'conditional_expression', 'children': ['90', '92', '95'], 'value': 'if'},{'id': '90', 'type': 'list', 'children': ['91'], 'value': "['RoW']"},{'id': '91', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'in'},{'id': '93', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '95', 'type': 'list', 'children': [], 'value': '[]'},{'id': '96', 'type': 'elif_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'exclusive'},{'id': '98', 'type': 'block', 'children': ['99', '109', '150']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'pattern_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'removed'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '104', 'type': 'expression_list', 'children': ['105', '108']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'list', 'children': [], 'value': '[]'},{'id': '109', 'type': 'while_statement', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '111', 'type': 'block', 'children': ['112', '121', '127']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '127', 'type': 'if_statement', 'children': ['128', '135']},{'id': '128', 'type': 'not_operator', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'removed'},{'id': '135', 'type': 'block', 'children': ['136', '143']},{'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': 'removed'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '154', 'type': 'if_statement', 'children': ['155', '162']},{'id': '155', 'type': 'boolean_operator', 'children': ['156', '159'], 'value': 'and'},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'not'},{'id': '157', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'in'},{'id': '160', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '172']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '167', 'type': 'conditional_expression', 'children': ['168', '170', '171'], 'value': 'if'},{'id': '168', 'type': 'unary_operator', 'children': ['169'], 'value': '-'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'biggest_first'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'lst'}
def _finish_filter(self, lst, key, include_self, exclusive, biggest_first): key = self._actual_key(key) locations = [x[0] for x in lst] if not include_self and key in locations: lst.pop(locations.index(key)) lst.sort(key=lambda x: x[1], reverse=biggest_first) lst = [x for x, y in lst] if key == 'RoW' and 'RoW' not in self and exclusive: return ['RoW'] if 'RoW' in lst else [] elif exclusive: removed, remaining = set(), [] while lst: current = lst.pop(0) faces = self[current] if not faces.intersection(removed): removed.update(faces) remaining.append(current) lst = remaining if 'RoW' not in self and 'RoW' in lst: lst[-1 if biggest_first else 0] = lst.pop(lst.index('RoW')) return lst
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersects'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'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': 'include_self'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'exclusive'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'biggest_first'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'only'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '38', '55', '61', '98']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'possibles'},{'id': '22', 'type': 'conditional_expression', 'children': ['23', '26', '29'], 'value': 'if'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'topology'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'only'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'dictionary_comprehension', 'children': ['30', '35']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'only'},{'id': '38', 'type': 'if_statement', 'children': ['39', '46']},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '43'], 'value': 'and'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'},{'id': '44', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'conditional_expression', 'children': ['49', '51', '54'], 'value': 'if'},{'id': '49', 'type': 'list', 'children': ['50'], 'value': "['RoW']"},{'id': '50', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': "'RoW'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'possibles'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '81', '90']},{'id': '65', 'type': 'tuple', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '67', 'type': 'tuple', 'children': ['68', '77']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'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': 'v'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'possibles'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'if_clause', 'children': ['91']},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'faces'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_finish_filter'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105', '106', '107', '108']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'include_self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'exclusive'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'biggest_first'}
def intersects(self, key, include_self=False, exclusive=False, biggest_first=True, only=None): possibles = self.topology if only is None else {k: self[k] for k in only} if key == 'RoW' and 'RoW' not in self: return ['RoW'] if 'RoW' in possibles else [] faces = self[key] lst = [ (k, (len(v.intersection(faces)), len(v))) for k, v in possibles.items() if (faces.intersection(v)) ] return self._finish_filter(lst, key, include_self, exclusive, biggest_first)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_by_key_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '6', 'type': 'block', 'children': ['7', '14', '30']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '28']},{'id': '20', 'type': 'attribute', 'children': ['21', '27']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key_func'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'result'}
def group_by_key_func(iterable, key_func): result = defaultdict(list) for item in iterable: result[key_func(item)].append(item) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '5', 'type': 'block', 'children': ['6', '14', '18', '51', '60']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '13']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10', '11', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'turn'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '32', '42']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '26'], 'value': '>'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '-'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '-'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x0'},{'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': 'turn'},{'id': '41', 'type': 'True', 'children': []},{'id': '42', 'type': 'elif_clause', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '<'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'turn'},{'id': '50', 'type': 'True', 'children': []},{'id': '51', 'type': 'if_statement', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'turn'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'tuple', 'children': ['56', '57', '58', '59']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'}
def sort(line): x0, y0, x1, y1 = line turn = False if abs(x1 - x0) > abs(y1 - y0): if x1 < x0: turn = True elif y1 < y0: turn = True if turn: return (x1, y1, x0, y0) return line
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'vectorizable_features'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fcs'},{'id': '5', 'type': 'block', 'children': ['6', '8', '21']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Discovers the ordered set of vectorizable features in ``fcs``.\n Returns a list of feature names, sorted lexicographically.\n Feature names are only included if the corresponding\n features are vectorizable (i.e., they are an instance of\n :class:`collections.Mapping`).\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'is_mapping'},{'id': '11', 'type': 'lambda', 'children': ['12', '14']},{'id': '12', 'type': 'lambda_parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'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']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'list_comprehension', 'children': ['29', '30', '33', '36']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fcs'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '36', 'type': 'if_clause', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'is_mapping'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}
def vectorizable_features(fcs): '''Discovers the ordered set of vectorizable features in ``fcs``. Returns a list of feature names, sorted lexicographically. Feature names are only included if the corresponding features are vectorizable (i.e., they are an instance of :class:`collections.Mapping`). ''' is_mapping = lambda obj: isinstance(obj, collections.Mapping) return sorted(set([name for fc in fcs for name in fc if is_mapping(fc[name])]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'extension_sort_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '5', 'type': 'block', 'children': ['6', '12', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '15', 'type': 'subscript', 'children': ['16', '23']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '22', 'type': 'integer', 'children': [], 'value': '2'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'conditional_expression', 'children': ['26', '29', '35'], 'value': 'if'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '31', 'type': 'tuple', 'children': ['32', '33', '34']},{'id': '32', 'type': 'string', 'children': [], 'value': "'ARB'"},{'id': '33', 'type': 'string', 'children': [], 'value': "'KHR'"},{'id': '34', 'type': 'string', 'children': [], 'value': "'OES'"},{'id': '35', 'type': 'tuple', 'children': ['36', '37']},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}
def extension_sort_key(extension): name = extension.name category = name.split('_', 2)[1] return (0, name) if category in ('ARB', 'KHR', 'OES') else (1, name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'estimate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '6', 'type': 'block', 'children': ['7', '11', '23']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'augmented_assignment', 'children': ['17', '18'], 'value': '+='},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'estimate'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'}
def estimate(self, upgrades): val = 0 for u in upgrades: val += u.estimate() return val
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'human_estimate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '6', 'type': 'block', 'children': ['7', '16']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'estimate'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20', '23', '30', '37', '44', '51', '60', '69', '78', '85']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '<'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '19', 'type': 'integer', 'children': [], 'value': '60'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': '"less than 1 minute"'},{'id': '23', 'type': 'elif_clause', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '<'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '26', 'type': 'integer', 'children': [], 'value': '300'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': '"less than 5 minutes"'},{'id': '30', 'type': 'elif_clause', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '<'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '33', 'type': 'integer', 'children': [], 'value': '600'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': '"less than 10 minutes"'},{'id': '37', 'type': 'elif_clause', 'children': ['38', '41']},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1800'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': '"less than 30 minutes"'},{'id': '44', 'type': 'elif_clause', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '47', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"less than 1 hour"'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '<'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '*'},{'id': '55', 'type': 'integer', 'children': [], 'value': '3'},{'id': '56', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"less than 3 hours"'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '66']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '<'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '*'},{'id': '64', 'type': 'integer', 'children': [], 'value': '6'},{'id': '65', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"less than 6 hours"'},{'id': '69', 'type': 'elif_clause', 'children': ['70', '75']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '<'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '*'},{'id': '73', 'type': 'integer', 'children': [], 'value': '12'},{'id': '74', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': '"less than 12 hours"'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '<'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '81', 'type': 'integer', 'children': [], 'value': '86400'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': '"less than 1 day"'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': '"more than 1 day"'}
def human_estimate(self, upgrades): val = self.estimate(upgrades) if val < 60: return "less than 1 minute" elif val < 300: return "less than 5 minutes" elif val < 600: return "less than 10 minutes" elif val < 1800: return "less than 30 minutes" elif val < 3600: return "less than 1 hour" elif val < 3 * 3600: return "less than 3 hours" elif val < 6 * 3600: return "less than 6 hours" elif val < 12 * 3600: return "less than 12 hours" elif val < 86400: return "less than 1 day" else: return "more than 1 day"
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pre_upgrade_checks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '6', 'type': 'block', 'children': ['7', '11', '53', '95', '101']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'global_pre_upgrade'},{'id': '16', 'type': 'block', 'children': ['17', '28']},{'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': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_setup_log_prefix'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'plugin_id'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '28', 'type': 'try_statement', 'children': ['29', '34']},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'except_clause', 'children': ['35', '39']},{'id': '35', 'type': 'as_pattern', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '37', 'type': 'as_pattern_target', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '39', 'type': 'block', 'children': ['40']},{'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': 'errors'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'tuple', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '56', 'type': 'block', 'children': ['57', '68']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_setup_log_prefix'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'plugin_id'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '68', 'type': 'try_statement', 'children': ['69', '76']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pre_upgrade'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'except_clause', 'children': ['77', '81']},{'id': '77', 'type': 'as_pattern', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '79', 'type': 'as_pattern_target', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'errors'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'tuple', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_teardown_log_prefix'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_check_errors'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '108', 'type': 'concatenated_string', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"Pre-upgrade check for %s failed with the"'},{'id': '110', 'type': 'string', 'children': [], 'value': '" following errors:"'}
def pre_upgrade_checks(self, upgrades): errors = [] for check in self.global_pre_upgrade: self._setup_log_prefix(plugin_id=check.__name__) try: check() except RuntimeError as e: errors.append((check.__name__, e.args)) for u in upgrades: self._setup_log_prefix(plugin_id=u.name) try: u.pre_upgrade() except RuntimeError as e: errors.append((u.name, e.args)) self._teardown_log_prefix() self._check_errors(errors, "Pre-upgrade check for %s failed with the" " following errors:")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'post_upgrade_checks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '6', 'type': 'block', 'children': ['7', '11', '53', '95', '101']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '14', 'type': 'block', 'children': ['15', '26']},{'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': '_setup_log_prefix'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'plugin_id'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'try_statement', 'children': ['27', '34']},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'post_upgrade'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'except_clause', 'children': ['35', '39']},{'id': '35', 'type': 'as_pattern', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '37', 'type': 'as_pattern_target', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '39', 'type': 'block', 'children': ['40']},{'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': 'errors'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'tuple', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'global_post_upgrade'},{'id': '58', 'type': 'block', 'children': ['59', '70']},{'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': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_setup_log_prefix'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'plugin_id'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '70', 'type': 'try_statement', 'children': ['71', '76']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'except_clause', 'children': ['77', '81']},{'id': '77', 'type': 'as_pattern', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '79', 'type': 'as_pattern_target', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'e'},{'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': 'errors'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'tuple', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '91', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '_teardown_log_prefix'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_check_errors'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '108', 'type': 'concatenated_string', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"Post-upgrade check for %s failed with the "'},{'id': '110', 'type': 'string', 'children': [], 'value': '"following errors:"'}
def post_upgrade_checks(self, upgrades): errors = [] for u in upgrades: self._setup_log_prefix(plugin_id=u.name) try: u.post_upgrade() except RuntimeError as e: errors.append((u.name, e.args)) for check in self.global_post_upgrade: self._setup_log_prefix(plugin_id=check.__name__) try: check() except RuntimeError as e: errors.append((check.__name__, e.args)) self._teardown_log_prefix() self._check_errors(errors, "Post-upgrade check for %s failed with the " "following errors:")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_upgrades'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'history'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16', '28', '131', '162', '184', '188', '241', '264']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'history'},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '15'], 'value': 'or'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'history'},{'id': '15', 'type': 'dictionary', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'graph_outgoing'},{'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': '_create_graph'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'history'},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '36']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'history'},{'id': '36', 'type': 'block', 'children': ['37', '42']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '40', 'type': 'list', 'children': ['41'], 'value': '[node_id, ]'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '42', 'type': 'while_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '44', 'type': 'block', 'children': ['45', '53', '89']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '52', 'type': 'argument_list', 'children': []},{'id': '53', 'type': 'try_statement', 'children': ['54', '77']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'graph_outgoing'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '73']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '73', 'type': 'if_clause', 'children': ['74']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '!='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '77', 'type': 'except_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': '"Ghost upgrade %s detected"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'in'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '93', 'type': 'block', 'children': ['94', '100', '127']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'depends_on'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '103']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'depends_on'},{'id': '103', 'type': 'block', 'children': ['104', '120']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'graph_outgoing'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '109', 'type': 'list_comprehension', 'children': ['110', '111', '116']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'graph_outgoing'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '116', 'type': 'if_clause', 'children': ['117']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '!='},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '127', 'type': 'delete_statement', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '131', 'type': 'for_statement', 'children': ['132', '135', '141']},{'id': '132', 'type': 'pattern_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'depends_on'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'depends_on'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'if_statement', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'not'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '159'], 'value': '%'},{'id': '156', 'type': 'concatenated_string', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': '"Upgrade %s depends on an unknown"'},{'id': '158', 'type': 'string', 'children': [], 'value': '" upgrade %s"'},{'id': '159', 'type': 'tuple', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'node_id'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '165', 'type': 'list_comprehension', 'children': ['166', '167', '175']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '175', 'type': 'if_clause', 'children': ['176']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '183'], 'value': '=='},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '183', 'type': 'integer', 'children': [], 'value': '0'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'topo_order'},{'id': '187', 'type': 'list', 'children': [], 'value': '[]'},{'id': '188', 'type': 'while_statement', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '190', 'type': 'block', 'children': ['191', '199', '206']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'node_n'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '198', 'type': 'argument_list', 'children': []},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'topo_order'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'node_n'},{'id': '206', 'type': 'for_statement', 'children': ['207', '208', '211']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'node_m'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'graph_outgoing'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'node_n'},{'id': '211', 'type': 'block', 'children': ['212', '228']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'node_m'},{'id': '217', 'type': 'list_comprehension', 'children': ['218', '219', '224']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '219', 'type': 'for_in_clause', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'node_m'},{'id': '224', 'type': 'if_clause', 'children': ['225']},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': '!='},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'node_n'},{'id': '228', 'type': 'if_statement', 'children': ['229', '233']},{'id': '229', 'type': 'not_operator', 'children': ['230']},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'node_m'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'start_nodes'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'node_m'},{'id': '241', 'type': 'for_statement', 'children': ['242', '245', '251']},{'id': '242', 'type': 'pattern_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'graph_incoming'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'if_statement', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'raise_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'binary_operator', 'children': ['260', '263'], 'value': '%'},{'id': '260', 'type': 'concatenated_string', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': '"The upgrades have at least one cyclic "'},{'id': '262', 'type': 'string', 'children': [], 'value': '"dependency involving %s."'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '264', 'type': 'return_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '267', 'type': 'argument_list', 'children': ['268', '274']},{'id': '268', 'type': 'lambda', 'children': ['269', '271']},{'id': '269', 'type': 'lambda_parameters', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'upgrades'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'topo_order'}
def order_upgrades(self, upgrades, history=None): history = history or {} graph_incoming, graph_outgoing = self._create_graph(upgrades, history) for node_id in six.iterkeys(history): start_nodes = [node_id, ] while start_nodes: node = start_nodes.pop() try: for d in graph_outgoing[node]: graph_incoming[d] = [x for x in graph_incoming[d] if x != node] except KeyError: warnings.warn("Ghost upgrade %s detected" % node) if node in graph_incoming: depends_on = graph_incoming[node] for d in depends_on: graph_outgoing[d] = [x for x in graph_outgoing[d] if x != node] start_nodes.append(d) del graph_incoming[node] for node_id, depends_on in six.iteritems(graph_incoming): for d in depends_on: if d not in graph_incoming: raise RuntimeError("Upgrade %s depends on an unknown" " upgrade %s" % (node_id, d)) start_nodes = [x for x in six.iterkeys(graph_incoming) if len(graph_incoming[x]) == 0] topo_order = [] while start_nodes: node_n = start_nodes.pop() topo_order.append(node_n) for node_m in graph_outgoing[node_n]: graph_incoming[node_m] = [x for x in graph_incoming[node_m] if x != node_n] if not graph_incoming[node_m]: start_nodes.append(node_m) for node, edges in six.iteritems(graph_incoming): if edges: raise RuntimeError("The upgrades have at least one cyclic " "dependency involving %s." % node) return map(lambda x: upgrades[x], topo_order)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_field'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'not'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'InvalidQueryParams'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'dictionary_splat', 'children': ['19']},{'id': '19', 'type': 'dictionary', 'children': ['20', '30', '33']},{'id': '20', 'type': 'pair', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'detail'"},{'id': '22', 'type': 'binary_operator', 'children': ['23', '27'], 'value': '%'},{'id': '23', 'type': 'concatenated_string', 'children': ['24', '25', '26']},{'id': '24', 'type': 'string', 'children': [], 'value': '\'The sort query param value of "%s" is \''},{'id': '25', 'type': 'string', 'children': [], 'value': "'invalid. That field does not exist on the '"},{'id': '26', 'type': 'string', 'children': [], 'value': "'resource being requested.'"},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'raw_field'},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'links'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'LINK'},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'parameter'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'PARAM'}
def _validate_field(param, fields): if param.field not in fields: raise InvalidQueryParams(**{ 'detail': 'The sort query param value of "%s" is ' 'invalid. That field does not exist on the ' 'resource being requested.' % param.raw_field, 'links': LINK, 'parameter': PARAM, })
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_no_rels'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rels'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'in'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rels'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'InvalidQueryParams'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'dictionary_splat', 'children': ['19']},{'id': '19', 'type': 'dictionary', 'children': ['20', '30', '33']},{'id': '20', 'type': 'pair', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': "'detail'"},{'id': '22', 'type': 'binary_operator', 'children': ['23', '27'], 'value': '%'},{'id': '23', 'type': 'concatenated_string', 'children': ['24', '25', '26']},{'id': '24', 'type': 'string', 'children': [], 'value': '\'The sort query param value of "%s" is not \''},{'id': '25', 'type': 'string', 'children': [], 'value': "'supported. Sorting on relationships is not '"},{'id': '26', 'type': 'string', 'children': [], 'value': "'currently supported'"},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'raw_field'},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'links'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'LINK'},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'parameter'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'PARAM'}
def _validate_no_rels(param, rels): if param.field in rels: raise InvalidQueryParams(**{ 'detail': 'The sort query param value of "%s" is not ' 'supported. Sorting on relationships is not ' 'currently supported' % param.raw_field, 'links': LINK, 'parameter': PARAM, })
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'init'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '35', '50', '66']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'rels'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'relationships'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'all_fields'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '29'], 'value': 'or'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_param_as_list'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '29', 'type': 'list', 'children': ['30'], 'value': '[goldman.config.SORT]'},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'goldman'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'SORT'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '47']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Sortable'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '53', 'type': 'block', 'children': ['54', '60']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_validate_no_rels'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rels'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': '_validate_field'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}
def init(req, model): rels = model.relationships fields = model.all_fields params = req.get_param_as_list('sort') or [goldman.config.SORT] params = [Sortable(param.lower()) for param in params] for param in params: _validate_no_rels(param, rels) _validate_field(param, fields) return params
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_allposts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '27', '48', '57', '61', '65', '225', '240']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "''' Return all posts in blog sorted by date\n\t\t'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'posts'},{'id': '17', 'type': 'argument_list', 'children': ['18', '21', '24']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'blog'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'try_statement', 'children': ['28', '35']},{'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': 'total_posts'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '34', 'type': 'string', 'children': [], 'value': "'total_posts'"},{'id': '35', 'type': 'except_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'raise_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'phasetumblr_errors'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'TumblrBlogException'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '46', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '56'], 'value': '+'},{'id': '52', 'type': '()', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '/'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'total_posts'},{'id': '55', 'type': 'integer', 'children': [], 'value': '10'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'all_posts'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'posts_ids'},{'id': '64', 'type': 'list', 'children': [], 'value': '[]'},{'id': '65', 'type': 'for_statement', 'children': ['66', '67', '71']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '71', 'type': 'block', 'children': ['72', '78', '87', '108', '116']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '*'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '77', 'type': 'integer', 'children': [], 'value': '10'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '86'], 'value': '*'},{'id': '82', 'type': '()', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'integer', 'children': [], 'value': '10'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'posts'},{'id': '90', 'type': 'subscript', 'children': ['91', '107']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'posts'},{'id': '97', 'type': 'argument_list', 'children': ['98', '101', '104']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'blog'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '107', 'type': 'string', 'children': [], 'value': "'posts'"},{'id': '108', 'type': 'if_statement', 'children': ['109', '114']},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'posts'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'break_statement', 'children': []},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'posts'},{'id': '119', 'type': 'block', 'children': ['120', '128', '137', '147', '151', '159', '167', '181', '189', '197', '203', '209', '216']},{'id': '120', 'type': 'if_statement', 'children': ['121', '126']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': 'in'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '124', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'posts_ids'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'continue_statement', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'split_body'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'string', 'children': [], 'value': "'body'"},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'split_body'},{'id': '142', 'type': 'argument_list', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'string', 'children': [], 'value': "'body'"},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '150', 'type': 'dictionary', 'children': []},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '155', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '164']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '163', 'type': 'string', 'children': [], 'value': "'link'"},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '166', 'type': 'string', 'children': [], 'value': "'post_url'"},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '171', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '176', 'type': 'argument_list', 'children': ['177', '180']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '179', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d %H:%M:%S %Z'"},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '186']},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '185', 'type': 'string', 'children': [], 'value': "'tags'"},{'id': '186', 'type': 'subscript', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '188', 'type': 'string', 'children': [], 'value': "'tags'"},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '193', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '196', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '201', 'type': 'string', 'children': [], 'value': "'body'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '207', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'all_posts'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'posts_ids'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '224', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'newlist'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'all_posts'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '234', 'type': 'lambda', 'children': ['235', '237']},{'id': '235', 'type': 'lambda_parameters', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '239', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'newlist'}
def get_allposts(self): ''' Return all posts in blog sorted by date ''' result = self.client.posts(self.blog, offset = 0, limit = 1) try: total_posts = result['total_posts'] except: raise phasetumblr_errors.TumblrBlogException(result['meta']['msg']) delta = (total_posts / 10) + 1 all_posts = [] posts_ids = [] for j in range(delta): start = j * 10 end = (j + 1) * 10 posts = self.client.posts(self.blog, offset = start, limit = end)['posts'] if not len(posts): break for i in posts: if i['id'] in posts_ids: continue description = split_body(i['body']) body = split_body(i['body'], 1) post = {} post['title'] = i['title'] post['link'] = i['post_url'] post['date'] = datetime.strptime(i['date'], '%Y-%m-%d %H:%M:%S %Z') post['tags'] = i['tags'] post['id'] = i['id'] post['body'] = body post['description'] = description all_posts.append(post) posts_ids.append(i['id']) newlist = sorted(all_posts, key=lambda k: k['date']) return newlist
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict_by_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'block', 'children': ['6', '15']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_func'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '21', 'type': 'argument_list', 'children': ['22', '27']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_func'}
def sort_dict_by_key(obj): sort_func = lambda x: x[0] return OrderedDict(sorted(obj.items(), key=sort_func))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortBy'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'block', 'children': ['8', '10', '16', '45']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''sort results by given criteria'''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'criteria'},{'id': '13', 'type': 'list', 'children': ['14', '15'], 'value': "['seeds', 'size']"},{'id': '14', 'type': 'string', 'children': [], 'value': "'seeds'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'in'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'criteria'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '32', 'type': 'argument_list', 'children': ['33', '36', '42']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '44', 'type': 'True', 'children': []},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}
def sortBy(self, *args): '''sort results by given criteria''' criteria = ['seeds', 'size'] for k in args: if k in criteria: self.results = sorted( self.results, key=attrgetter(k), reverse=True) return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rate_limited'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'max_per_second'},{'id': '5', 'type': 'block', 'children': ['6', '9', '20', '25', '129']},{'id': '6', 'type': 'import_statement', 'children': ['7']},{'id': '7', 'type': 'dotted_name', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'min_request_time'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'max_per_second'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'last_time_called'},{'id': '23', 'type': 'list', 'children': ['24'], 'value': '[None]'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'function_definition', 'children': ['26', '27', '29']},{'id': '26', 'type': 'function_name', 'children': [], 'value': 'decorate'},{'id': '27', 'type': 'parameters', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '29', 'type': 'block', 'children': ['30', '121']},{'id': '30', 'type': 'function_definition', 'children': ['31', '32', '37']},{'id': '31', 'type': 'function_name', 'children': [], 'value': 'rate_limited_function'},{'id': '32', 'type': 'parameters', 'children': ['33', '35']},{'id': '33', 'type': 'list_splat_pattern', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '35', 'type': 'dictionary_splat_pattern', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'block', 'children': ['38', '97', '107', '119']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'last_time_called'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'block', 'children': ['43', '57']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '54'], 'value': '-'},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'last_time_called'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'if_statement', 'children': ['58', '65', '74']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '<'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'expression_list', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'chrw'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'TimeIsBackToFront'},{'id': '73', 'type': 'string', 'children': [], 'value': '"Call the Doc!"'},{'id': '74', 'type': 'elif_clause', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '<'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'min_request_time'},{'id': '78', 'type': 'block', 'children': ['79', '89']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': '"Last request was {0}, should be at least {1}"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'min_request_time'},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'expression_list', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'chrw'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'RequestRateTooHigh'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '102', 'type': 'argument_list', 'children': ['103', '105']},{'id': '103', 'type': 'list_splat', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '105', 'type': 'dictionary_splat', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'last_time_called'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'update_wrapper'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'rate_limited_function'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'decorate'}
def rate_limited(max_per_second): import datetime min_request_time = datetime.timedelta(seconds=max_per_second) last_time_called = [None] def decorate(func): def rate_limited_function(*args, **kwargs): if last_time_called[0]: delta = datetime.datetime.now() - last_time_called[0] if delta < datetime.timedelta.min: raise chrw.exceptions.TimeIsBackToFront, "Call the Doc!" elif delta < min_request_time: msg = "Last request was {0}, should be at least {1}".format( delta, min_request_time ) raise chrw.exceptions.RequestRateTooHigh, msg ret = func(*args, **kwargs) last_time_called[0] = datetime.datetime.now() return ret return functools.update_wrapper(rate_limited_function, func) return decorate
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'monotony'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13', '16', '33']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': '=='},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'elif_clause', 'children': ['17', '29']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'}
def monotony(seq): if seq == sorted(seq): return 1 elif seq == list(reversed(sorted(seq))): return -1 else: return 0
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variables'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Variable'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_docfilter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'doc'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '38', 'type': 'argument_list', 'children': []}
def variables(self): p = lambda o: isinstance(o, Variable) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'classes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_docfilter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'doc'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '38', 'type': 'argument_list', 'children': []}
def classes(self): p = lambda o: isinstance(o, Class) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'functions'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Function'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_docfilter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'doc'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '38', 'type': 'argument_list', 'children': []}
def functions(self): p = lambda o: isinstance(o, Function) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'submodules'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Module'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_docfilter'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'doc'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '38', 'type': 'argument_list', 'children': []}
def submodules(self): p = lambda o: isinstance(o, Module) and self._docfilter(o) return sorted(filter(p, self.doc.values()))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'class_variables'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '26']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '9', 'type': 'lambda', 'children': ['10', '12']},{'id': '10', 'type': 'lambda_parameters', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Variable'},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_docfilter'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'p'},{'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': 'doc'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '37', 'type': 'argument_list', 'children': []}
def class_variables(self): p = lambda o: isinstance(o, Variable) and self.module._docfilter(o) return filter(p, self.doc.values())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'BEDIterator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'scoreType'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'dropAfter'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '24', '28', '45', '101']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'chromsSeen'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '37']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '36'], 'value': '=='},{'id': '30', 'type': 'attribute', 'children': ['31', '35']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '36', 'type': 'string', 'children': [], 'value': '"str"'},{'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': 'filehandle'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '45', 'type': 'if_statement', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'try_statement', 'children': ['49', '78']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pind'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ProgressIndicator'},{'id': '55', 'type': 'argument_list', 'children': ['56', '68', '71']},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'totalToDo'},{'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': 'getsize'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'messagePrefix'},{'id': '70', 'type': 'string', 'children': [], 'value': '"completed"'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'messageSuffix'},{'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'},{'id': '74', 'type': 'string', 'children': [], 'value': '"of processing "'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '78', 'type': 'except_clause', 'children': ['79', '85']},{'id': '79', 'type': 'as_pattern', 'children': ['80', '83']},{'id': '80', 'type': 'tuple', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '83', 'type': 'as_pattern_target', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '85', 'type': 'block', 'children': ['86', '97']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'},{'id': '95', 'type': 'string', 'children': [], 'value': '"BEDIterator -- warning: "'},{'id': '96', 'type': 'string', 'children': [], 'value': '"unable to show progress for stream"'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '100', 'type': 'False', 'children': []},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '104', 'type': 'block', 'children': ['105', '124', '134', '165', '208', '222', '311', '387', '390']},{'id': '105', 'type': 'if_statement', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '107', 'type': 'block', 'children': ['108', '118']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'pind'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'done'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'pind'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'showProgress'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'if_statement', 'children': ['125', '132']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '131'], 'value': '=='},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'string', 'children': [], 'value': '""'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'continue_statement', 'children': []},{'id': '134', 'type': 'try_statement', 'children': ['135', '147']},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'parseBEDString'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'scoreType'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'dropAfter'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'dropAfter'},{'id': '147', 'type': 'except_clause', 'children': ['148', '152']},{'id': '148', 'type': 'as_pattern', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'GenomicIntervalError'},{'id': '150', 'type': 'as_pattern_target', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'raise_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'BEDError'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'binary_operator', 'children': ['158', '164'], 'value': '+'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '163'], 'value': '+'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '163', 'type': 'string', 'children': [], 'value': '" on line "'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '165', 'type': 'if_statement', 'children': ['166', '184']},{'id': '166', 'type': '()', 'children': ['167']},{'id': '167', 'type': 'boolean_operator', 'children': ['168', '176'], 'value': 'and'},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '173'], 'value': 'and'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_NAME'},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'is'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '175', 'type': 'None', 'children': []},{'id': '176', 'type': '()', 'children': ['177']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': '>'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'raise_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'BEDError'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'binary_operator', 'children': ['190', '205'], 'value': '+'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '204'], 'value': '+'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '201'], 'value': '+'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '200'], 'value': '+'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '199'], 'value': '+'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'},{'id': '195', 'type': 'string', 'children': [], 'value': '"bed file "'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '199', 'type': 'string', 'children': [], 'value': '" not sorted by element name"'},{'id': '200', 'type': 'string', 'children': [], 'value': '" found "'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '204', 'type': 'string', 'children': [], 'value': '" after "'},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '208', 'type': 'if_statement', 'children': ['209', '212']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'is'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '211', 'type': 'None', 'children': []},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'chromsSeen'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '222', 'type': 'if_statement', 'children': ['223', '238']},{'id': '223', 'type': 'boolean_operator', 'children': ['224', '231'], 'value': 'and'},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '228'], 'value': 'and'},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': 'is'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '227', 'type': 'None', 'children': []},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'is'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '230', 'type': 'None', 'children': []},{'id': '231', 'type': 'comparison_operator', 'children': ['232', '235'], 'value': '=='},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '238', 'type': 'block', 'children': ['239', '275']},{'id': '239', 'type': 'if_statement', 'children': ['240', '251']},{'id': '240', 'type': 'boolean_operator', 'children': ['241', '244'], 'value': 'and'},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_START'},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '>'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'raise_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'BEDError'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'binary_operator', 'children': ['257', '271'], 'value': '+'},{'id': '257', 'type': 'binary_operator', 'children': ['258', '270'], 'value': '+'},{'id': '258', 'type': 'binary_operator', 'children': ['259', '266'], 'value': '+'},{'id': '259', 'type': 'binary_operator', 'children': ['260', '265'], 'value': '+'},{'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '+'},{'id': '261', 'type': 'string', 'children': [], 'value': '"bed file "'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '265', 'type': 'string', 'children': [], 'value': '" not sorted by start index - saw item "'},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '270', 'type': 'string', 'children': [], 'value': '" before "'},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '275', 'type': 'if_statement', 'children': ['276', '287']},{'id': '276', 'type': 'boolean_operator', 'children': ['277', '280'], 'value': 'and'},{'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '=='},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_END'},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '284'], 'value': '>'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'raise_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'BEDError'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'binary_operator', 'children': ['293', '307'], 'value': '+'},{'id': '293', 'type': 'binary_operator', 'children': ['294', '306'], 'value': '+'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '302'], 'value': '+'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '301'], 'value': '+'},{'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '+'},{'id': '297', 'type': 'string', 'children': [], 'value': '"bed file "'},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '301', 'type': 'string', 'children': [], 'value': '" not sorted by end index - saw item "'},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '306', 'type': 'string', 'children': [], 'value': '" before "'},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '311', 'type': 'if_statement', 'children': ['312', '323']},{'id': '312', 'type': 'boolean_operator', 'children': ['313', '316'], 'value': 'and'},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '315'], 'value': 'is'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '315', 'type': 'None', 'children': []},{'id': '316', 'type': 'comparison_operator', 'children': ['317', '320'], 'value': '!='},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '323', 'type': 'block', 'children': ['324', '378']},{'id': '324', 'type': 'if_statement', 'children': ['325', '353']},{'id': '325', 'type': 'boolean_operator', 'children': ['326', '338', '339'], 'value': 'and'},{'id': '326', 'type': '()', 'children': ['327']},{'id': '327', 'type': 'boolean_operator', 'children': ['328', '335'], 'value': 'or'},{'id': '328', 'type': 'boolean_operator', 'children': ['329', '332'], 'value': 'or'},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '331'], 'value': '=='},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_START'},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': '=='},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_END'},{'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': '=='},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'sortedby'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'ITERATOR_SORTED_CHROM'},{'id': '338', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '339', 'type': '()', 'children': ['340']},{'id': '340', 'type': 'boolean_operator', 'children': ['341', '346'], 'value': 'or'},{'id': '341', 'type': 'comparison_operator', 'children': ['342', '345'], 'value': 'in'},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'chromsSeen'},{'id': '346', 'type': 'comparison_operator', 'children': ['347', '350'], 'value': '>'},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '353', 'type': 'block', 'children': ['354', '369']},{'id': '354', 'type': 'try_statement', 'children': ['355', '362']},{'id': '355', 'type': 'block', 'children': ['356']},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'assignment', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'e_fn'},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'filehandle'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '362', 'type': 'except_clause', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'assignment', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'e_fn'},{'id': '368', 'type': 'string', 'children': [], 'value': '"UNNAMED STREAM"'},{'id': '369', 'type': 'raise_statement', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'BEDError'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'binary_operator', 'children': ['374', '377'], 'value': '+'},{'id': '374', 'type': 'binary_operator', 'children': ['375', '376'], 'value': '+'},{'id': '375', 'type': 'string', 'children': [], 'value': '"BED file "'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'e_fn'},{'id': '377', 'type': 'string', 'children': [], 'value': '" not sorted by chrom"'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'chromsSeen'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'yield', 'children': ['389']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'assignment', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'e'}
def BEDIterator(filehandle, sortedby=None, verbose=False, scoreType=int, dropAfter=None): chromsSeen = set() prev = None if type(filehandle).__name__ == "str": filehandle = open(filehandle) if verbose: try: pind = ProgressIndicator(totalToDo=os.path.getsize(filehandle.name), messagePrefix="completed", messageSuffix="of processing " + filehandle.name) except (AttributeError, OSError) as e: sys.stderr.write("BEDIterator -- warning: " + "unable to show progress for stream") verbose = False for line in filehandle: if verbose: pind.done = filehandle.tell() pind.showProgress() if line.strip() == "": continue try: e = parseBEDString(line, scoreType, dropAfter=dropAfter) except GenomicIntervalError as e: raise BEDError(str(e) + " on line " + line) if ((sortedby == ITERATOR_SORTED_NAME and prev is not None) and (prev.name > e.name)): raise BEDError("bed file " + filehandle.name + " not sorted by element name" + " found " + e.name + " after " + prev.name) if prev is None: chromsSeen.add(e.chrom) if prev is not None and sortedby is not None and e.chrom == prev.chrom: if sortedby == ITERATOR_SORTED_START and prev.start > e.start: raise BEDError("bed file " + filehandle.name + " not sorted by start index - saw item " + str(prev) + " before " + str(e)) if sortedby == ITERATOR_SORTED_END and prev.end > e.end: raise BEDError("bed file " + filehandle.name + " not sorted by end index - saw item " + str(prev) + " before " + str(e)) if prev is not None and prev.chrom != e.chrom: if (sortedby == ITERATOR_SORTED_START or sortedby == ITERATOR_SORTED_END or sortedby == ITERATOR_SORTED_CHROM) and\ (e.chrom in chromsSeen or prev.chrom > e.chrom): try: e_fn = filehandle.name except AttributeError: e_fn = "UNNAMED STREAM" raise BEDError("BED file " + e_fn + " not sorted by chrom") chromsSeen.add(e.chrom) yield e prev = e
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compress_and_sort_index'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '40', '50', '63', '69', '80', '88', '100', '107', '118', '129', '135', '154', '161']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'idx_fname'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'string', 'children': [], 'value': "'{name}.{date}.mbox.csv'"},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'dictionary_splat', 'children': ['15']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '18', 'type': 'try_statement', 'children': ['19', '35']},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '27', 'type': 'argument_list', 'children': ['28', '32']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'idx_fname'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '34', 'type': 'string', 'children': [], 'value': "'excel-tab'"},{'id': '35', 'type': 'except_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'False', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '45', '48']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'reader'},{'id': '48', 'type': 'if_clause', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'gzip_idx_fname'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'idx_fname'},{'id': '68', 'type': 'string', 'children': [], 'value': "'.gz'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '72', 'type': 'list', 'children': ['73', '78'], 'value': "[\n '\\xef\\xbb\\xbf\n 'start', 'length',\n ]"},{'id': '73', 'type': 'concatenated_string', 'children': ['74', '75', '77']},{'id': '74', 'type': 'string', 'children': [], 'value': "'\\xef\\xbb\\xbf\n '"},{'id': '75', 'type': 'ERROR', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '77', 'type': 'string', 'children': [], 'value': "', '"},{'id': '78', 'type': 'ERROR', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'cStringIO'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '99', 'type': 'string', 'children': [], 'value': "'excel-tab'"},{'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': 'writer'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sorted_index'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'compressed_index'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'inline_compress_chunk'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '128', 'type': 'argument_list', 'children': []},{'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': 's'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'with_statement', 'children': ['136', '146']},{'id': '136', 'type': 'with_clause', 'children': ['137']},{'id': '137', 'type': 'with_item', 'children': ['138']},{'id': '138', 'type': 'as_pattern', 'children': ['139', '144']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'gzip_idx_fname'},{'id': '143', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '144', 'type': 'as_pattern_target', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'compressed_index'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'idx_fname'},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'True', 'children': []}
def compress_and_sort_index(self): idx_fname = '{name}.{date}.mbox.csv'.format(**self.__dict__) try: reader = csv.reader(open(idx_fname), dialect='excel-tab') except IOError: return False index = [x for x in reader if x] sorted_index = sorted(index, key=itemgetter(0)) gzip_idx_fname = idx_fname + '.gz' header = [ '\xef\xbb\xbf 'start', 'length', ] s = cStringIO.StringIO() writer = csv.writer(s, dialect='excel-tab') writer.writerow(header) for line in sorted_index: writer.writerow(line) compressed_index = inline_compress_chunk(s.getvalue()) s.close() with open(gzip_idx_fname, 'ab') as fp: fp.write(compressed_index) os.remove(idx_fname) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '16', 'type': 'argument_list', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'lambda', 'children': ['27', '29']},{'id': '27', 'type': 'lambda_parameters', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'}
def _sort(self): self.versions = OrderedDict(sorted(self.versions.items(), key=lambda v: v[0]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_workspace_activities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'brain'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'block', 'children': ['9', '16', '32']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'mb'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'queryUtility'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'IMicroblogTool'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'mb'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'context_values'},{'id': '23', 'type': 'argument_list', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'brain'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'getObject'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'list_comprehension', 'children': ['34', '71']},{'id': '34', 'type': 'dictionary', 'children': ['35', '40', '43', '48']},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'subject'"},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'creator'},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'verb'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'published'"},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'object'"},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '50', 'type': 'dictionary', 'children': ['51', '61']},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'datetime'"},{'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': 'item'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'title'"},{'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': 'item'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': "'%d %B %Y, %H:%M'"},{'id': '71', 'type': 'for_in_clause', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'items'}
def get_workspace_activities(brain, limit=1): mb = queryUtility(IMicroblogTool) items = mb.context_values(brain.getObject(), limit=limit) return [ { 'subject': item.creator, 'verb': 'published', 'object': item.text, 'time': { 'datetime': item.date.strftime('%Y-%m-%d'), 'title': item.date.strftime('%d %B %Y, %H:%M'), } } for item in items ]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '6', 'type': 'block', 'children': ['7', '38']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'key_func'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'try_statement', 'children': ['13', '20']},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '20', 'type': 'except_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'try_statement', 'children': ['24', '29']},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '29', 'type': 'except_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key_func'}
def sort_by(items, attr): def key_func(item): try: return getattr(item, attr) except AttributeError: try: return item[attr] except TypeError: getattr(item, attr) return sorted(items, key=key_func)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_migrations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '35']},{'id': '6', 'type': 'if_statement', 'children': ['7', '11']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_sorted_migrations'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_sorted_migrations'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '19', 'type': 'argument_list', 'children': ['20', '27']},{'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': 'migration_registry'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'lambda', 'children': ['30', '32']},{'id': '30', 'type': 'lambda_parameters', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'migration_tuple'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'migration_tuple'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_sorted_migrations'}
def sorted_migrations(self): if not self._sorted_migrations: self._sorted_migrations = sorted( self.migration_registry.items(), key=lambda migration_tuple: migration_tuple[0]) return self._sorted_migrations
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorter'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'generated'},{'id': '5', 'type': 'block', 'children': ['6', '36', '42']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '27']},{'id': '10', 'type': 'tuple', 'children': ['11', '19']},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'generated'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'list_comprehension', 'children': ['44', '57']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'pairs'}
def _sorter(generated): pairs = [(os.path.dirname(f), os.path.basename(f)) for f in set(list(generated))] pairs.sort() return [os.path.join(pair[0], pair[1]) for pair in pairs]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'regionsIntersection'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'collapse'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '21', '28', '45', '49', '53', '346']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'collapseRegions'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'collapseRegions'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '28', 'type': 'if_statement', 'children': ['29', '42']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '36'], 'value': 'or'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '35'], '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': 'identifier', 'children': [], 'value': 's1_c'},{'id': '35', 'type': 'integer', 'children': [], 'value': '0'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '=='},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'list', 'children': [], 'value': '[]'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '48', 'type': 'list', 'children': [], 'value': '[]'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '63']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '63', 'type': 'block', 'children': ['64', '85', '111', '162', '209', '321', '325']},{'id': '64', 'type': 'if_statement', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '84'], 'value': '+'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'},{'id': '77', 'type': 'string', 'children': [], 'value': '"processing from s1_c : "'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '110'], 'value': '+'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '106'], 'value': '+'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '105'], 'value': '+'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'string', 'children': [], 'value': '"i = "'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '105', 'type': 'string', 'children': [], 'value': '" and j = "'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '110', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '111', 'type': 'while_statement', 'children': ['112', '157']},{'id': '112', 'type': '()', 'children': ['113']},{'id': '113', 'type': 'boolean_operator', 'children': ['114', '120'], 'value': 'and'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '<'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'boolean_operator', 'children': ['122', '133'], 'value': 'or'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '128'], 'value': '<'},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '133', 'type': '()', 'children': ['134']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '146'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '141'], 'value': '=='},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '152'], 'value': '<='},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'augmented_assignment', 'children': ['160', '161'], 'value': '+='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'if_statement', 'children': ['163', '207']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '182', '183'], 'value': 'or'},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '171'], 'value': 'or'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '>='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '177'], 'value': '>'},{'id': '172', 'type': 'attribute', 'children': ['173', '176']},{'id': '173', 'type': 'subscript', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '182', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '196'], 'value': 'and'},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '191'], 'value': '=='},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '191', 'type': 'attribute', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': '>='},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'continue_statement', 'children': []},{'id': '209', 'type': 'while_statement', 'children': ['210', '221']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '216'], 'value': '<'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '221', 'type': 'block', 'children': ['222', '238', '254', '270', '289', '296', '300']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '227', 'type': 'argument_list', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '243', 'type': 'argument_list', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '249', 'type': 'attribute', 'children': ['250', '253']},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'GenomicInterval'},{'id': '259', 'type': 'argument_list', 'children': ['260', '265', '266', '267', '268', '269']},{'id': '260', 'type': 'attribute', 'children': ['261', '264']},{'id': '261', 'type': 'subscript', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '267', 'type': 'string', 'children': [], 'value': '"X"'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'string', 'children': [], 'value': '"+"'},{'id': '270', 'type': 'if_statement', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'binary_operator', 'children': ['282', '288'], 'value': '+'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '284'], 'value': '+'},{'id': '283', 'type': 'string', 'children': [], 'value': '"\\tadding to overlaps: "'},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '288', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'augmented_assignment', 'children': ['298', '299'], 'value': '+='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '299', 'type': 'integer', 'children': [], 'value': '1'},{'id': '300', 'type': 'if_statement', 'children': ['301', '319']},{'id': '301', 'type': 'boolean_operator', 'children': ['302', '308'], 'value': 'or'},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '304'], 'value': '>='},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '314'], 'value': '!='},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'subscript', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 's1_c'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'break_statement', 'children': []},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'augmented_assignment', 'children': ['323', '324'], 'value': '-='},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '324', 'type': 'integer', 'children': [], 'value': '1'},{'id': '325', 'type': 'if_statement', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '335']},{'id': '330', 'type': 'attribute', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'binary_operator', 'children': ['337', '345'], 'value': '+'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '+'},{'id': '338', 'type': 'string', 'children': [], 'value': '"\\tmoving s2_c index back to "'},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 's2_c'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '345', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '346', 'type': 'return_statement', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'res'}
def regionsIntersection(s1, s2, collapse=True): debug = False s1_c = collapseRegions(s1) s2_c = collapseRegions(s2) if len(s1_c) == 0 or len(s2_c) == 0: return [] res = [] j = 0 for i in range(0, len(s1_c)): if debug: sys.stderr.write("processing from s1_c : " + str(s1_c[i]) + "\n") if debug: sys.stderr.write("i = " + str(i) + " and j = " + str(j) + "\n") while (j < len(s2_c) and (s2_c[j].chrom < s1_c[i].chrom or (s2_c[j].chrom == s1_c[i].chrom and s2_c[j].end <= s1_c[i].start))): j += 1 if j >= len(s2_c) or s2_c[j].chrom > s1_c[i].chrom or \ (s2_c[j].chrom == s1_c[i].chrom and s2_c[j].start >= s1_c[i].end): continue while s2_c[j].start < s1_c[i].end: s = max(s1_c[i].start, s2_c[j].start) e = min(s1_c[i].end, s2_c[j].end) overlap = GenomicInterval(s1_c[i].chrom, s, e, "X", 0, "+") if debug: sys.stderr.write("\tadding to overlaps: " + str(overlap) + "\n") res.append(overlap) j += 1 if j >= len(s2_c) or s2_c[j].chrom != s1_c[i].chrom: break j -= 1 if debug: sys.stderr.write("\tmoving s2_c index back to " + str(s2_c[j]) + "\n") return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bucketIterator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '6', 'type': 'block', 'children': ['7', '66', '200', '204', '208', '216']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'check_sorted'},{'id': '9', 'type': 'parameters', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'if_statement', 'children': ['14', '48']},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '19', '20'], 'value': 'and'},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '30'], 'value': 'or'},{'id': '22', 'type': '()', 'children': ['23']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '>'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '30', 'type': '()', 'children': ['31']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '40'], 'value': 'and'},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': '>'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'GenomicIntervalError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'binary_operator', 'children': ['54', '62'], 'value': '+'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '61'], 'value': '+'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'},{'id': '56', 'type': 'string', 'children': [], 'value': '"elements not sorted. Saw "'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '61', 'type': 'string', 'children': [], 'value': '" before "'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '66', 'type': 'function_definition', 'children': ['67', '68', '74']},{'id': '67', 'type': 'function_name', 'children': [], 'value': 'updateOpen'},{'id': '68', 'type': 'parameters', 'children': ['69', '70', '71', '72', '73']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bucketStart'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'bucketEnd'},{'id': '74', 'type': 'block', 'children': ['75', '117']},{'id': '75', 'type': 'while_statement', 'children': ['76', '111']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '83'], 'value': 'and'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '82'], 'value': '>'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '93'], 'value': 'or'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '92'], 'value': '<'},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '103'], 'value': 'and'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '102'], 'value': '=='},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '103', 'type': '()', 'children': ['104']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '<='},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bucketStart'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'heappop'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '117', 'type': 'while_statement', 'children': ['118', '162']},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '127', '128'], 'value': 'and'},{'id': '119', 'type': '()', 'children': ['120']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '126'], 'value': 'is'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '128', 'type': '()', 'children': ['129']},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '140'], 'value': 'or'},{'id': '130', 'type': '()', 'children': ['131']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '139'], 'value': '<'},{'id': '132', 'type': 'attribute', 'children': ['133', '138']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '140', 'type': '()', 'children': ['141']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '152'], 'value': 'and'},{'id': '142', 'type': '()', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '151'], 'value': '=='},{'id': '144', 'type': 'attribute', 'children': ['145', '150']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '152', 'type': '()', 'children': ['153']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '161'], 'value': '<'},{'id': '154', 'type': 'attribute', 'children': ['155', '160']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'bucketEnd'},{'id': '162', 'type': 'block', 'children': ['163', '171', '194']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'elementIterator'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '__next__'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'if_statement', 'children': ['172', '192']},{'id': '172', 'type': 'boolean_operator', 'children': ['173', '179', '180'], 'value': 'or'},{'id': '173', 'type': '()', 'children': ['174']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '<'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '179', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '180', 'type': '()', 'children': ['181']},{'id': '181', 'type': 'boolean_operator', 'children': ['182', '187'], 'value': 'and'},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': '=='},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'bucketChrom'},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '<='},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'bucketStart'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'continue_statement', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'heappush'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'openHeap'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'openElems'},{'id': '203', 'type': 'list', 'children': [], 'value': '[]'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '207', 'type': 'None', 'children': []},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'elementIter'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'AutoApplyIterator'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'check_sorted'},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'buckets'},{'id': '219', 'type': 'block', 'children': ['220', '269', '284', '301']},{'id': '220', 'type': 'if_statement', 'children': ['221', '251']},{'id': '221', 'type': 'boolean_operator', 'children': ['222', '225'], 'value': 'and'},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '224', 'type': 'None', 'children': []},{'id': '225', 'type': '()', 'children': ['226']},{'id': '226', 'type': 'boolean_operator', 'children': ['227', '235'], 'value': 'or'},{'id': '227', 'type': '()', 'children': ['228']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': '<'},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '235', 'type': '()', 'children': ['236']},{'id': '236', 'type': 'boolean_operator', 'children': ['237', '244'], 'value': 'and'},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '241'], 'value': '=='},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '<'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'raise_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'GenomicIntervalError'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'binary_operator', 'children': ['257', '265'], 'value': '+'},{'id': '257', 'type': 'binary_operator', 'children': ['258', '264'], 'value': '+'},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '+'},{'id': '259', 'type': 'string', 'children': [], 'value': '"regions-of-interest are not sorted. Saw "'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '264', 'type': 'string', 'children': [], 'value': '" before "'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'updateOpen'},{'id': '272', 'type': 'argument_list', 'children': ['273', '274', '275', '278', '281']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'openElems'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'elementIter'},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'yield', 'children': ['286']},{'id': '286', 'type': 'expression_list', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '288', 'type': 'list_comprehension', 'children': ['289', '290', '293']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '290', 'type': 'for_in_clause', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'openElems'},{'id': '293', 'type': 'if_clause', 'children': ['294']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '298'], 'value': '<'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'prevBucket'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'bucket'}
def bucketIterator(elements, buckets): def check_sorted(current, previous): if (previous is not None) and \ ((previous.chrom > current.chrom) or ((previous.chrom == current.chrom) and (previous.start > current.start))): raise GenomicIntervalError("elements not sorted. Saw " + str(previous) + " before " + str(current)) def updateOpen(openHeap, elementIterator, bucketChrom, bucketStart, bucketEnd): while len(openHeap) > 0 and ((openHeap[0].chrom < bucketChrom) or ((openHeap[0].chrom == bucketChrom) and (openHeap[0].end <= bucketStart))): heappop(openHeap) while (elementIterator.peek() is not None) and \ ((elementIterator.peek().chrom < bucketChrom) or ((elementIterator.peek().chrom == bucketChrom) and (elementIterator.peek().start < bucketEnd))): e = elementIterator.__next__() if (e.chrom < bucketChrom) or \ (e.chrom == bucketChrom and e.end <= bucketStart): continue heappush(openHeap, e) openElems = [] prevBucket = None elementIter = AutoApplyIterator(elements, check_sorted) for bucket in buckets: if prevBucket is not None and ((bucket.chrom < prevBucket.chrom) or (bucket.chrom == prevBucket.chrom and bucket.start < prevBucket.start)): raise GenomicIntervalError("regions-of-interest are not sorted. Saw " + str(prevBucket) + " before " + str(bucket)) updateOpen(openElems, elementIter, bucket.chrom, bucket. start, bucket.end) yield bucket, [x for x in openElems if x.start < bucket.end] prevBucket = bucket
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ordered'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '28', '45', '51', '63']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'unordered_dict'},{'id': '13', 'type': 'dictionary_comprehension', 'children': ['14', '17']},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'generator'},{'id': '23', 'type': 'argument_list', 'children': ['24', '26']},{'id': '24', 'type': 'list_splat', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '26', 'type': 'dictionary_splat', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '44']},{'id': '38', 'type': 'attribute', 'children': ['39', '43']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unordered_dict'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'unordered_dict'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result'}
def _ordered(generator, *args, **kwargs): unordered_dict = {k: v for k, v in generator(*args, **kwargs)} keys = sorted(list(dict(unordered_dict).keys())) result = OrderedDict() for key in keys: result[key] = unordered_dict[key] return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'str2dict_keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'str_in'},{'id': '5', 'type': 'block', 'children': ['6', '8', '15', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Extracts the keys from a string that represents a dict and returns them\n sorted by key.\n Args:\n str_in (string) that contains python dict\n Returns:\n (list) with keys or None if no valid dict was found\n Raises:\n -\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str2dict'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str_in'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'}
def str2dict_keys(str_in): ''' Extracts the keys from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with keys or None if no valid dict was found Raises: - ''' tmp_dict = str2dict(str_in) if tmp_dict is None: return None return sorted([k for k in tmp_dict])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'str2dict_values'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'str_in'},{'id': '5', 'type': 'block', 'children': ['6', '8', '15', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Extracts the values from a string that represents a dict and returns them\n sorted by key.\n Args:\n str_in (string) that contains python dict\n Returns:\n (list) with values or None if no valid dict was found\n Raises:\n -\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str2dict'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str_in'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'generator_expression', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'tmp_dict'}
def str2dict_values(str_in): ''' Extracts the values from a string that represents a dict and returns them sorted by key. Args: str_in (string) that contains python dict Returns: (list) with values or None if no valid dict was found Raises: - ''' tmp_dict = str2dict(str_in) if tmp_dict is None: return None return [tmp_dict[key] for key in sorted(k for k in tmp_dict)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'keyword_separator', 'children': []},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'include_keys'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'exclude_keys'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'use_default_excludes'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '17', 'type': 'False', 'children': []},{'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': 'to_json'},{'id': '22', 'type': 'argument_list', 'children': ['23', '37']},{'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': 'to_dict'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31', '34']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'include_keys'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'include_keys'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'exclude_keys'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'exclude_keys'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'use_default_excludes'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'use_default_excludes'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'pretty'}
def to_json(self, *, include_keys=None, exclude_keys=None, use_default_excludes=True, pretty=False): return to_json( self.to_dict( include_keys=include_keys, exclude_keys=exclude_keys, use_default_excludes=use_default_excludes), pretty=pretty)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_annotations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '19', '22', '25', '28', '31']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '14', 'type': 'lambda', 'children': ['15', '18']},{'id': '15', 'type': 'lambda_parameters', 'children': ['16']},{'id': '16', 'type': 'list_splat_pattern', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '18', 'type': 'True', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mindepth'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'maxdepth'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'followannotated'},{'id': '27', 'type': 'True', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'public'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '39', '226', '335']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '38', 'type': 'list', 'children': [], 'value': '[]'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '<='},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mindepth'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'block', 'children': ['44', '70', '142', '151']},{'id': '44', 'type': 'try_statement', 'children': ['45', '63']},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '51', 'type': 'argument_list', 'children': ['52', '55', '60']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '__ANNOTATIONS_KEY__'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '63', 'type': 'except_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': 'annotations_by_ctx'},{'id': '69', 'type': 'dictionary', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '73']},{'id': '71', 'type': 'not_operator', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '79', '122']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '79', 'type': 'block', 'children': ['80', '87', '104']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_method_function'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '92', 'type': 'argument_list', 'children': ['93', '96', '101']},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '100', 'type': 'identifier', 'children': [], 'value': '__ANNOTATIONS_KEY__'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '104', 'type': 'if_statement', 'children': ['105', '107']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '__ANNOTATIONS_KEY__'},{'id': '122', 'type': 'elif_clause', 'children': ['123', '127']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'isfunction'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '133', 'type': 'argument_list', 'children': ['134', '137']},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '__ANNOTATIONS_KEY__'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '145', 'type': 'conditional_expression', 'children': ['146', '147', '150'], 'value': 'if'},{'id': '146', 'type': 'tuple', 'children': []},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '151', 'type': 'for_statement', 'children': ['152', '155', '156']},{'id': '152', 'type': 'pattern_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'annotations_by_ctx'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'annotations'},{'id': '160', 'type': 'block', 'children': ['161', '174', '185', '197']},{'id': '161', 'type': 'if_statement', 'children': ['162', '167']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'StopPropagation'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'annotation_types'},{'id': '174', 'type': 'if_statement', 'children': ['175', '183']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '179'], 'value': 'and'},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'is'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '179', 'type': 'not_operator', 'children': ['180']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'propagate'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'continue_statement', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'override'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'augmented_assignment', 'children': ['192', '193'], 'value': '+='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '193', 'type': 'tuple', 'children': ['194']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '196', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '197', 'type': 'if_statement', 'children': ['198', '218']},{'id': '198', 'type': '()', 'children': ['199']},{'id': '199', 'type': 'boolean_operator', 'children': ['200', '212'], 'value': 'and'},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '206'], 'value': 'and'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '206', 'type': 'not_operator', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '226', 'type': 'if_statement', 'children': ['227', '241']},{'id': '227', 'type': 'boolean_operator', 'children': ['228', '231'], 'value': 'or'},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': '>='},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'mindepth'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': '()', 'children': ['232']},{'id': '232', 'type': 'boolean_operator', 'children': ['233', '236'], 'value': 'and'},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '>'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'maxdepth'},{'id': '235', 'type': 'integer', 'children': [], 'value': '0'},{'id': '236', 'type': '()', 'children': ['237']},{'id': '237', 'type': 'boolean_operator', 'children': ['238', '239'], 'value': 'or'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '239', 'type': 'not_operator', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'followannotated'},{'id': '241', 'type': 'block', 'children': ['242', '261']},{'id': '242', 'type': 'if_statement', 'children': ['243', '246', '252']},{'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'is'},{'id': '244', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '245', 'type': 'None', 'children': []},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '250', 'type': 'list', 'children': ['251'], 'value': '[target]'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '261', 'type': 'for_statement', 'children': ['262', '265', '269']},{'id': '262', 'type': 'pattern_list', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'if_statement', 'children': ['271', '284']},{'id': '271', 'type': 'boolean_operator', 'children': ['272', '281'], 'value': 'and'},{'id': '272', 'type': '()', 'children': ['273']},{'id': '273', 'type': 'boolean_operator', 'children': ['274', '279'], 'value': 'or'},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '278'], 'value': '!='},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '277', 'type': 'integer', 'children': [], 'value': '0'},{'id': '278', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '279', 'type': 'not_operator', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'public'},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'not'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '283', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '284', 'type': 'block', 'children': ['285', '299']},{'id': '285', 'type': 'if_statement', 'children': ['286', '297']},{'id': '286', 'type': 'boolean_operator', 'children': ['287', '291'], 'value': 'and'},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ismethod'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'string', 'children': [], 'value': "'im_'"},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'continue_statement', 'children': []},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'augmented_assignment', 'children': ['301', '302'], 'value': '+='},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'get_annotations'},{'id': '306', 'type': 'argument_list', 'children': ['307', '310', '313', '316', '319', '324', '329', '332']},{'id': '307', 'type': 'keyword_argument', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '310', 'type': 'keyword_argument', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'mindepth'},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '-'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'mindepth'},{'id': '323', 'type': 'integer', 'children': [], 'value': '1'},{'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'maxdepth'},{'id': '326', 'type': 'binary_operator', 'children': ['327', '328'], 'value': '-'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'maxdepth'},{'id': '328', 'type': 'integer', 'children': [], 'value': '1'},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'followannotated'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'followannotated'},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '334', 'type': 'identifier', 'children': [], 'value': '_history'},{'id': '335', 'type': 'return_statement', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'result'}
def get_annotations( cls, target, exclude=None, ctx=None, select=lambda *p: True, mindepth=0, maxdepth=0, followannotated=True, public=True, _history=None ): result = [] if mindepth <= 0: try: annotations_by_ctx = get_property( elt=target, key=Annotation.__ANNOTATIONS_KEY__, ctx=ctx ) except TypeError: annotations_by_ctx = {} if not annotations_by_ctx: if ismethod(target): func = get_method_function(target) annotations_by_ctx = get_property( elt=func, key=Annotation.__ANNOTATIONS_KEY__, ctx=ctx ) if not annotations_by_ctx: annotations_by_ctx = get_property( elt=func, key=Annotation.__ANNOTATIONS_KEY__ ) elif isfunction(target): annotations_by_ctx = get_property( elt=target, key=Annotation.__ANNOTATIONS_KEY__ ) exclude = () if exclude is None else exclude for elt, annotations in annotations_by_ctx: for annotation in annotations: if isinstance(annotation, StopPropagation): exclude += annotation.annotation_types if elt is not target and not annotation.propagate: continue if annotation.override: exclude += (annotation.__class__, ) if (isinstance(annotation, cls) and not isinstance(annotation, exclude) and select(target, ctx, annotation)): result.append(annotation) if mindepth >= 0 or (maxdepth > 0 and (result or not followannotated)): if _history is None: _history = [target] else: _history.append(target) for name, member in getmembers(target): if (name[0] != '_' or not public) and member not in _history: if ismethod(target) and name.startswith('im_'): continue result += cls.get_annotations( target=member, exclude=exclude, ctx=ctx, select=select, mindepth=mindepth - 1, maxdepth=maxdepth - 1, followannotated=followannotated, _history=_history ) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_filenames'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '5', 'type': 'block', 'children': ['6', '20']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'{}/*.pkl'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_f_to_i'}
def get_filenames(dirname): filenames = glob.glob('{}/*.pkl'.format(dirname)) return sorted(filenames, key=_f_to_i)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_states'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_list'},{'id': '6', 'type': 'block', 'children': ['7', '15', '73']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '24']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_pair'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_convert_list_of_dict_to_tuple'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_list'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '39', '49']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '35'], 'value': 'in'},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_pair'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '35', 'type': 'list', 'children': ['36', '37', '38'], 'value': "['data','measure','meta']"},{'id': '36', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'measure'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'meta'"},{'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': 'sorted_states'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_state_value_sort'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_pair'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_state_key_function'},{'id': '49', 'type': 'elif_clause', 'children': ['50', '55']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '=='},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_pair'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'string', 'children': [], 'value': "'groupings'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'for_statement', 'children': ['57', '58', '64']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_pair'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_groupings_values_sort'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_states'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'grouping'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sorted_states'}
def sort_states(states, sort_list): sorted_states= states.copy() for sort_pair in reversed( _convert_list_of_dict_to_tuple(sort_list) ): if sort_pair[0].lstrip('-') in ['data','measure','meta']: sorted_states= _state_value_sort(sorted_states, sort_pair, _state_key_function) elif sort_pair[0] == 'groupings': for grouping in reversed(sort_pair[1]): sorted_states= _groupings_values_sort(sorted_states, grouping) return sorted_states
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '11', '14', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'all_categories'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'SearchSortKey'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'order_key'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'SearchOrderKey'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'descending'},{'id': '24', 'type': 'block', 'children': ['25', '50', '64', '73', '82', '119', '123', '148', '320']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '28', 'type': 'dictionary', 'children': ['29', '32', '35', '40', '45']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'page'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'search'"},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'term'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'cats'"},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'order_key'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_get_page_content'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'a_to_last_page'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'string', 'children': [], 'value': '\'.//div[@class="rightpages"]/a[2]\''},{'id': '82', 'type': 'if_statement', 'children': ['83', '85', '90']},{'id': '83', 'type': 'not_operator', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'a_to_last_page'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'total_pages'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92', '102', '112']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'last_page_url'},{'id': '95', 'type': 'subscript', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a_to_last_page'},{'id': '99', 'type': 'integer', 'children': [], 'value': '0'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '101', 'type': 'string', 'children': [], 'value': "'href'"},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '105', 'type': 'subscript', 'children': ['106', '111']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'extract_url_query_parameter'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'last_page_url'},{'id': '110', 'type': 'string', 'children': [], 'value': '"offset"'},{'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': 'total_pages'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'torrent_stubs'},{'id': '122', 'type': 'list', 'children': [], 'value': '[]'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '126', 'type': 'generator_expression', 'children': ['127', '128', '136']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'.//table//tr'"},{'id': '136', 'type': 'if_clause', 'children': ['137']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'},{'id': '138', 'type': 'string', 'children': [], 'value': "'tlistrow'"},{'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': 'x'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '147', 'type': 'string', 'children': [], 'value': "''"},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '151', 'type': 'block', 'children': ['152', '161', '182', '191', '212', '225', '233', '261', '289', '300', '313']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': "'td'"},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'category_value'},{'id': '164', 'type': 'subscript', 'children': ['165', '181']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'extract_url_query_parameter'},{'id': '167', 'type': 'argument_list', 'children': ['168', '180']},{'id': '168', 'type': 'subscript', 'children': ['169', '179']},{'id': '169', 'type': 'attribute', 'children': ['170', '178']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '179', 'type': 'string', 'children': [], 'value': "'href'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'cats'"},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'Category'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'lookup_category'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'category_value'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'torrent_id'},{'id': '194', 'type': 'subscript', 'children': ['195', '211']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'extract_url_query_parameter'},{'id': '197', 'type': 'argument_list', 'children': ['198', '210']},{'id': '198', 'type': 'subscript', 'children': ['199', '209']},{'id': '199', 'type': 'attribute', 'children': ['200', '208']},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'attrib'},{'id': '209', 'type': 'string', 'children': [], 'value': "'href'"},{'id': '210', 'type': 'string', 'children': [], 'value': '"tid"'},{'id': '211', 'type': 'integer', 'children': [], 'value': '0'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '215', 'type': 'attribute', 'children': ['216', '224']},{'id': '216', 'type': 'call', 'children': ['217', '222']},{'id': '217', 'type': 'attribute', 'children': ['218', '221']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'file_size'},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '231', 'type': 'integer', 'children': [], 'value': '3'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '233', 'type': 'if_statement', 'children': ['234', '243', '255']},{'id': '234', 'type': 'call', 'children': ['235', '242']},{'id': '235', 'type': 'attribute', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '239', 'type': 'integer', 'children': [], 'value': '4'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'seeders'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '253', 'type': 'integer', 'children': [], 'value': '4'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '255', 'type': 'else_clause', 'children': ['256']},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'seeders'},{'id': '260', 'type': 'None', 'children': []},{'id': '261', 'type': 'if_statement', 'children': ['262', '271', '283']},{'id': '262', 'type': 'call', 'children': ['263', '270']},{'id': '263', 'type': 'attribute', 'children': ['264', '269']},{'id': '264', 'type': 'attribute', 'children': ['265', '268']},{'id': '265', 'type': 'subscript', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '267', 'type': 'integer', 'children': [], 'value': '5'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '270', 'type': 'argument_list', 'children': []},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'leechers'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '281', 'type': 'integer', 'children': [], 'value': '5'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '283', 'type': 'else_clause', 'children': ['284']},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'leechers'},{'id': '288', 'type': 'None', 'children': []},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'downloads'},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'attribute', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'cell_td_elems'},{'id': '298', 'type': 'integer', 'children': [], 'value': '6'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'TorrentStub'},{'id': '305', 'type': 'argument_list', 'children': ['306', '307', '308', '309', '310', '311', '312']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'torrent_id'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'seeders'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'leechers'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'file_size'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'downloads'},{'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': 'torrent_stubs'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'stub'},{'id': '320', 'type': 'return_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'SearchResultPage'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325', '326', '327', '328', '329', '330']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'order_key'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'total_pages'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'torrent_stubs'}
def search(self, terms, category=Category.all_categories, page=1, sort_key=SearchSortKey.date, order_key=SearchOrderKey.descending): params = { 'page': 'search', 'term': terms, 'cats': category.value, 'sort': sort_key.value, 'order': order_key.value, } r = requests.get(self.base_url, params=params) content = self._get_page_content(r) a_to_last_page = content.findall('.//div[@class="rightpages"]/a[2]') if not a_to_last_page: total_pages = 1 else: last_page_url = a_to_last_page[0].attrib['href'] offset = extract_url_query_parameter(last_page_url, "offset")[0] total_pages = int(offset) torrent_stubs = [] rows = (x for x in content.findall('.//table//tr') if 'tlistrow' in x.attrib.get('class', '')) for row in rows: cell_td_elems = row.findall('td') category_value = extract_url_query_parameter( cell_td_elems[0].find('a').attrib['href'], 'cats')[0] category = Category.lookup_category(category_value) torrent_id = extract_url_query_parameter( cell_td_elems[1].find('a').attrib['href'], "tid")[0] name = cell_td_elems[1].find('a').text file_size = cell_td_elems[3].text if cell_td_elems[4].text.isdigit(): seeders = int(cell_td_elems[4].text) else: seeders = None if cell_td_elems[5].text.isdigit(): leechers = int(cell_td_elems[5].text) else: leechers = None downloads = int(cell_td_elems[6].text) stub = TorrentStub(torrent_id, name, category, seeders, leechers, file_size, downloads) torrent_stubs.append(stub) return SearchResultPage( terms, category, sort_key, order_key, page, total_pages, torrent_stubs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'partition'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'mapped_values'},{'id': '6', 'type': 'block', 'children': ['7', '16', '31']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'partitioned_data'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '21']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mapped_values'},{'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': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'partitioned_data'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'partitioned_data'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '36', 'type': 'argument_list', 'children': []}
def partition(self, mapped_values): partitioned_data = collections.defaultdict(list) for key, value in mapped_values: partitioned_data[key].append(value) return partitioned_data.items()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cond_int'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'conkey'},{'id': '6', 'type': 'block', 'children': ['7', '19', '25']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'numrx'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'conkey'},{'id': '19', 'type': 'if_statement', 'children': ['20', '22']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'conkey'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'}
def cond_int(self, conkey): m = re.match(self.numrx, conkey) if not m: return conkey return int(m.group(1))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_conkeys'},{'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': 'prefix'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '42', '48']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conkeys'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_COND_PREFIXES'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'augmented_assignment', 'children': ['19', '20'], 'value': '+='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'conkeys'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23', '37']},{'id': '23', 'type': 'list_comprehension', 'children': ['24', '25', '30']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '30', 'type': 'if_clause', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'cond_int'},{'id': '42', 'type': 'if_statement', 'children': ['43', '45']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'conkeys'},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '51', '54']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'conkeys'},{'id': '54', 'type': 'if_clause', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'prefix'}
def sorted_conkeys(self, prefix=None): conkeys = [] for cond in _COND_PREFIXES: conkeys += sorted([key for key in self.conditions if key.startswith(cond)], key=self.cond_int) if not prefix: return conkeys return [key for key in conkeys if key.startswith(prefix)]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'isordinal'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'block', 'children': ['6', '11', '34', '69']},{'id': '6', 'type': 'import_statement', 'children': ['7']},{'id': '7', 'type': 'aliased_import', 'children': ['8', '10']},{'id': '8', 'type': 'dotted_name', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '11', 'type': 'if_statement', 'children': ['12', '26']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '17'], 'value': '=='},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'expression_list', 'children': ['29', '30']},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': '()', 'children': ['31']},{'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"number of observations equals the "'},{'id': '33', 'type': 'string', 'children': [], 'value': '"number of unique values."'},{'id': '34', 'type': 'if_statement', 'children': ['35', '43']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '38', 'type': 'argument_list', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '64']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'equal'},{'id': '55', 'type': 'argument_list', 'children': ['56', '63']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'expression_list', 'children': ['67', '68']},{'id': '67', 'type': 'False', 'children': []},{'id': '68', 'type': 'string', 'children': [], 'value': '"elements are not integer or strings."'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'expression_list', 'children': ['71', '72']},{'id': '71', 'type': 'True', 'children': []},{'id': '72', 'type': 'string', 'children': [], 'value': '"is ordinal"'}
def isordinal(x): import numpy as np if len(x) == len(np.unique(x)): return False, ("number of observations equals the " "number of unique values.") if not isinstance(x[0], str): if not np.all(np.equal(np.mod(x, 1), 0)): return False, "elements are not integer or strings." return True, "is ordinal"
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'block', 'children': ['8', '30']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'add_get_param'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'FILTER_DELIMITER'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'list_comprehension', 'children': ['21', '27']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ELEMENT_DELIMITER'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'elements'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, *sort): self.add_get_param('sort', FILTER_DELIMITER.join( [ELEMENT_DELIMITER.join(elements) for elements in sort])) return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'drop_null'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'camel'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '23', 'type': 'argument_list', 'children': ['24', '31', '34']},{'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': 'to_dict'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'drop_null'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'camel'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}
def to_json(self, drop_null=True, camel=False, indent=None, sort_keys=False): return json.dumps(self.to_dict(drop_null, camel), indent=indent, sort_keys=sort_keys)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_name'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '5', 'type': 'block', 'children': ['6', '61']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'last_name_key'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '10', 'type': 'block', 'children': ['11', '20', '34', '55']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "' '"},{'id': '20', 'type': 'if_statement', 'children': ['21', '27']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '26'], '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': 'identifier', 'children': [], 'value': 'parts'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'last_first'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '44'], 'value': '+'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '43'], 'value': '+'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'string', 'children': [], 'value': "' '"},{'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': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '51', 'type': 'slice', 'children': ['52', '53']},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'unary_operator', 'children': ['54'], 'value': '-'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'last_first'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '64', 'type': 'argument_list', 'children': ['65', '69']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'last_name_key'}
def sort_by_name(names): def last_name_key(full_name): parts = full_name.split(' ') if len(parts) == 1: return full_name.upper() last_first = parts[-1] + ' ' + ' '.join(parts[:-1]) return last_first.upper() return sorted(set(names), key=last_name_key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '47', '67']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '31']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '18', 'type': 'argument_list', 'children': ['19', '25']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'commits'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': "'author_mail'"},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'group'},{'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': 'users'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'merge_user_commits'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '64']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'users'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "'line_count'"},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '66', 'type': 'True', 'children': []},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'}
def sort(self): users = [] for _, group in itertools.groupby(sorted(self.commits), operator.attrgetter('author_mail')): if group: users.append(self.merge_user_commits(group)) self.sorted_commits = sorted(users, key=operator.attrgetter('line_count'), reverse=True) return self.sorted_commits
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '22', '33', '39', '45', '107', '121', '130']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'},{'id': '11', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'commits'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'commits'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'prev_line'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'prev_uuid'},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'commits'},{'id': '50', 'type': 'block', 'children': ['51', '95', '101']},{'id': '51', 'type': 'if_statement', 'children': ['52', '67']},{'id': '52', 'type': '()', 'children': ['53']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '59'], 'value': 'or'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '!='},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'prev_uuid'},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '!='},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'prev_line'},{'id': '66', 'type': 'integer', 'children': [], 'value': '1'},{'id': '67', 'type': 'block', 'children': ['68', '82', '91']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line_range'},{'id': '77', 'type': 'argument_list', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'prev_line'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'prev_line'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'prev_uuid'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'commit'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'line_range'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'line_number'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'prev_line'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'prev_commit'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sorted_commits'}
def sort(self): self.sorted_commits = [] if not self.commits: return self.sorted_commits prev_commit = self.commits.pop(0) prev_line = prev_commit.line_number prev_uuid = prev_commit.uuid for commit in self.commits: if (commit.uuid != prev_uuid or commit.line_number != (prev_line + 1)): prev_commit.lines = self.line_range(prev_commit.line_number, prev_line) self.sorted_commits.append(prev_commit) prev_commit = commit prev_line = commit.line_number prev_uuid = commit.uuid prev_commit.lines = self.line_range(prev_commit.line_number, prev_line) self.sorted_commits.append(prev_commit) return self.sorted_commits
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'truncate_most_common'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'truncation_length'},{'id': '6', 'type': 'block', 'children': ['7', '9', '26']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Sorts the counter and keeps only the most common items up to\n ``truncation_length`` in place.\n :type truncation_length: int\n '''"},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'keep_keys'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '14', 'type': 'generator_expression', 'children': ['15', '18']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'truncation_length'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '33']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'not'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'keep_keys'},{'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': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}
def truncate_most_common(self, truncation_length): ''' Sorts the counter and keeps only the most common items up to ``truncation_length`` in place. :type truncation_length: int ''' keep_keys = set(v[0] for v in self.most_common(truncation_length)) for key in self.keys(): if key not in keep_keys: self.pop(key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ordered_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keypath'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'open_interval'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '15', '30', '76', '86', '95', '103', '109', '128', '150', '159', '165', '169', '340']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'if_statement', 'children': ['16', '21']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': '=='},{'id': '17', 'type': 'subscript', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'keypath'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keypath'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keypath'},{'id': '27', 'type': 'slice', 'children': ['28', '29']},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'colon', 'children': []},{'id': '30', 'type': 'for_statement', 'children': ['31', '34', '39']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'instance'},{'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': 'iter_singleton_referents'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '49', '66']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_value_from_path'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'keypath'},{'id': '49', 'type': 'if_statement', 'children': ['50', '63']},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '56'], 'value': 'and'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '55', 'type': 'string', 'children': [], 'value': "'low'"},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '60'], 'value': '!='},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'list', 'children': [], 'value': '[]'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'if_statement', 'children': ['77', '83']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '82'], 'value': '=='},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'list', 'children': [], 'value': '[]'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '-'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '112', 'type': 'string', 'children': [], 'value': "'max'"},{'id': '113', 'type': 'block', 'children': ['114', '122']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '-'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '=='},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '131', 'type': 'string', 'children': [], 'value': "'mean'"},{'id': '132', 'type': 'block', 'children': ['133', '141']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'anchor'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sdiffs'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sdiffs'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '168', 'type': 'list', 'children': [], 'value': '[]'},{'id': '169', 'type': 'for_statement', 'children': ['170', '173', '177']},{'id': '170', 'type': 'pattern_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sdiffs'},{'id': '177', 'type': 'block', 'children': ['178', '184', '190']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '<='},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'diffs'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '190', 'type': 'if_statement', 'children': ['191', '192', '212', '258', '305']},{'id': '191', 'type': 'False', 'children': []},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '201', 'type': 'argument_list', 'children': ['202', '207']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '206', 'type': 'argument_list', 'children': []},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'elif_clause', 'children': ['213', '216']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '=='},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '215', 'type': 'string', 'children': [], 'value': "'max'"},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'if_statement', 'children': ['218', '219', '237']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'open_interval'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '228', 'type': 'argument_list', 'children': ['229', '234']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '237', 'type': 'else_clause', 'children': ['238']},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '247', 'type': 'argument_list', 'children': ['248', '253']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '257', 'type': 'argument_list', 'children': []},{'id': '258', 'type': 'elif_clause', 'children': ['259', '262']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '=='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '261', 'type': 'string', 'children': [], 'value': "'min'"},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'if_statement', 'children': ['264', '265', '284']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'open_interval'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '274', 'type': 'argument_list', 'children': ['275', '279']},{'id': '275', 'type': 'unary_operator', 'children': ['276'], 'value': '-'},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '283', 'type': 'argument_list', 'children': []},{'id': '284', 'type': 'else_clause', 'children': ['285']},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '294', 'type': 'argument_list', 'children': ['295', '300']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '299', 'type': 'argument_list', 'children': []},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '304', 'type': 'argument_list', 'children': []},{'id': '305', 'type': 'elif_clause', 'children': ['306', '309']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': '=='},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'distance_from'},{'id': '308', 'type': 'string', 'children': [], 'value': "'mean'"},{'id': '309', 'type': 'block', 'children': ['310', '321']},{'id': '310', 'type': 'if_statement', 'children': ['311', '319']},{'id': '311', 'type': 'comparison_operator', 'children': ['312', '315'], 'value': '=='},{'id': '312', 'type': 'binary_operator', 'children': ['313', '314'], 'value': '+'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'ix'},{'id': '314', 'type': 'integer', 'children': [], 'value': '1'},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '317', 'type': 'argument_list', 'children': ['318']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'sdiffs'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'continue_statement', 'children': []},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'IntervalCell'},{'id': '329', 'type': 'argument_list', 'children': ['330', '335']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '334', 'type': 'argument_list', 'children': []},{'id': '335', 'type': 'call', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '339', 'type': 'argument_list', 'children': []},{'id': '340', 'type': 'return_statement', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'results'}
def get_ordered_values(self, keypath, distance_from, open_interval=True): values = [] if keypath[0] == 'target': keypath = keypath[1:] for _, instance in self.iter_singleton_referents(): value = instance.get_value_from_path(keypath) if hasattr(value, 'low') and value.low != value.high: return [] values.append(float(value)) if len(values) == 0: return [] values = np.array(values) anchor = values.min() diffs = values - anchor if distance_from == 'max': anchor = values.max() diffs = anchor - values if distance_from == 'mean': anchor = values.mean() diffs = abs(anchor - values) sdiffs = np.unique(diffs) sdiffs.sort() results = [] for ix, el in enumerate(sdiffs): mask = diffs <= el vals = values[mask] if False: results.append(IntervalCell(vals.min(), vals.max())) elif distance_from == 'max': if open_interval: results.append(IntervalCell(vals.min(), np.inf)) else: results.append(IntervalCell(vals.min(), vals.min())) elif distance_from == 'min': if open_interval: results.append(IntervalCell(-np.inf, vals.max())) else: results.append(IntervalCell(vals.max(), vals.max())) elif distance_from == 'mean': if ix+1 == len(sdiffs): continue results.append(IntervalCell(vals.min(), vals.max())) return results
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gp_datdir'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'topN'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23', '35', '50', '56', '138', '145', '179', '201', '208', '270']},{'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': 'inDir'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'outDir'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'getWorkDirs'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'capitalize'},{'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': 'inDir'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'inDir'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '35', 'type': 'if_statement', 'children': ['36', '45']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'inDir'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': '"initial %s doesn\'t exist"'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'for_statement', 'children': ['57', '58', '64']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'inDir'},{'id': '64', 'type': 'block', 'children': ['65', '78', '90', '105', '115']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '68', 'type': 'subscript', 'children': ['69', '77']},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'inDir'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'loadtxt'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '104', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'augmented_assignment', 'children': ['107', '114'], 'value': '/='},{'id': '107', 'type': 'subscript', 'children': ['108', '111', '113']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '111', 'type': 'slice', 'children': ['112']},{'id': '112', 'type': 'colon', 'children': []},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'float', 'children': [], 'value': '1e6'},{'id': '115', 'type': 'if_statement', 'children': ['116', '125']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '124'], 'value': '>'},{'id': '117', 'type': 'subscript', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'augmented_assignment', 'children': ['128', '137'], 'value': '/='},{'id': '128', 'type': 'subscript', 'children': ['129', '132', '134']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'country'},{'id': '132', 'type': 'slice', 'children': ['133']},{'id': '133', 'type': 'colon', 'children': []},{'id': '134', 'type': 'slice', 'children': ['135', '136']},{'id': '135', 'type': 'integer', 'children': [], 'value': '3'},{'id': '136', 'type': 'colon', 'children': []},{'id': '137', 'type': 'float', 'children': [], 'value': '1e6'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '153', 'type': 'argument_list', 'children': ['154', '159', '176']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '161', 'type': 'lambda', 'children': ['162', '164']},{'id': '162', 'type': 'lambda_parameters', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'subscript', 'children': ['170', '173', '175']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'slice', 'children': ['174']},{'id': '174', 'type': 'colon', 'children': []},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '178', 'type': 'True', 'children': []},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'top_data'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '184', 'type': 'generator_expression', 'children': ['185', '193', '199']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'popitem'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '192', 'type': 'False', 'children': []},{'id': '193', 'type': 'for_in_clause', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'topN'},{'id': '199', 'type': 'if_clause', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'sorted_data'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'nSets'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'top_data'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'make_plot'},{'id': '211', 'type': 'argument_list', 'children': ['212', '219', '232', '239', '250', '255', '258', '261', '264', '267']},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'top_data'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '221', 'type': 'list_comprehension', 'children': ['222', '226']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'getOpts'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'nSets'},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'top_data'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'outDir'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '252', 'type': 'list', 'children': ['253', '254'], 'value': "[ 'at graph 1., 1.2', 'maxrows 2' ]"},{'id': '253', 'type': 'string', 'children': [], 'value': "'at graph 1., 1.2'"},{'id': '254', 'type': 'string', 'children': [], 'value': "'maxrows 2'"},{'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'ylabel'},{'id': '257', 'type': 'string', 'children': [], 'value': "'total population ({/Symbol \\664} 10^{6})'"},{'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'xlabel'},{'id': '260', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'rmargin'},{'id': '263', 'type': 'float', 'children': [], 'value': '0.99'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'tmargin'},{'id': '266', 'type': 'float', 'children': [], 'value': '0.85'},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '269', 'type': 'string', 'children': [], 'value': "'8.5in,8in'"},{'id': '270', 'type': 'return_statement', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'done'"}
def gp_datdir(initial, topN): inDir, outDir = getWorkDirs() initial = initial.capitalize() inDir = os.path.join(inDir, initial) if not os.path.exists(inDir): return "initial %s doesn't exist" % initial data = OrderedDict() for file in os.listdir(inDir): country = os.path.splitext(file)[0] file_url = os.path.join(inDir, file) data[country] = np.loadtxt(open(file_url, 'rb')) data[country][:, 1] /= 1e6 if data[country].shape[1] > 2: data[country][:, 3:] /= 1e6 logging.debug(data) sorted_data = OrderedDict(sorted( data.items(), key = lambda t: np.mean(t[1][:,1]), reverse = True )) top_data = OrderedDict( sorted_data.popitem(last = False) for i in xrange(topN) if sorted_data ) nSets = len(top_data) make_plot( data = top_data.values(), properties = [ getOpts(i) for i in xrange(nSets) ], titles = top_data.keys(), name = os.path.join(outDir, initial), key = [ 'at graph 1., 1.2', 'maxrows 2' ], ylabel = 'total population ({/Symbol \664} 10^{6})', xlabel = 'year', rmargin = 0.99, tmargin = 0.85, size='8.5in,8in' ) return 'done'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rankingEval'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '19', '30', '61', '69', '91', '99', '110', '114', '161', '167', '173']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n\t\tSorting the pop. base on the fitnessEval result\n\t\t'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'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': 'length'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fitnessNorm'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '38']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '38', 'type': 'block', 'children': ['39', '49']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '48']},{'id': '41', 'type': 'attribute', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'Ind'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fitnessEval'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Ind'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'fitness'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'maxFitness'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '77']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fitnessNorm'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '83', 'type': 'binary_operator', 'children': ['84', '90'], 'value': '/'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '-'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'maxFitness'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'maxFitness'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'fitnessSorted'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'fitnessNorm'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'probability'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '113', 'type': 'float', 'children': [], 'value': '2.0'},{'id': '114', 'type': 'for_statement', 'children': ['115', '116', '122']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '130']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'probability'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'fitnessSorted'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '140'], 'value': '+'},{'id': '131', 'type': '()', 'children': ['132']},{'id': '132', 'type': 'binary_operator', 'children': ['133', '137'], 'value': '/'},{'id': '133', 'type': '()', 'children': ['134']},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '-'},{'id': '135', 'type': 'integer', 'children': [], 'value': '2'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '150'], 'value': '/'},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '*'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '*'},{'id': '144', 'type': 'integer', 'children': [], 'value': '2'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'S'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': '()', 'children': ['151']},{'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '*'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '160'], 'value': '-'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'rankingComputed'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fitness'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'list', 'children': ['175', '176', '183'], 'value': '[fitnessAll, fitnessSorted[::-1], probability]'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'fitnessAll'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'fitnessSorted'},{'id': '178', 'type': 'slice', 'children': ['179', '180', '181']},{'id': '179', 'type': 'colon', 'children': []},{'id': '180', 'type': 'colon', 'children': []},{'id': '181', 'type': 'unary_operator', 'children': ['182'], 'value': '-'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'probability'}
def rankingEval(self): ''' Sorting the pop. base on the fitnessEval result ''' fitnessAll = numpy.zeros(self.length) fitnessNorm = numpy.zeros(self.length) for i in range(self.length): self.Ind[i].fitnessEval() fitnessAll[i] = self.Ind[i].fitness maxFitness = fitnessAll.max() for i in range(self.length): fitnessNorm[i] = (maxFitness - fitnessAll[i]) / maxFitness fitnessSorted = fitnessNorm.argsort() probability = numpy.zeros(self.length) S = 2.0 for i in range(self.length): probability[fitnessSorted[i]] = ((2-S)/self.length) + (2*i*(S-1))/(self.length*(self.length-1)) self.rankingComputed = 1 self.fitness = fitnessAll return [fitnessAll, fitnessSorted[::-1], probability]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortedbyAge'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '19', '40', '48']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n\t\tSorting the pop. base of the age\n\t\t'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ageAll'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'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': 'length'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '27']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ageAll'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '33', 'type': 'attribute', 'children': ['34', '39']},{'id': '34', 'type': 'subscript', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Ind'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'age'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ageSorted'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ageAll'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'return_statement', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ageSorted'},{'id': '51', 'type': 'slice', 'children': ['52', '53', '54']},{'id': '52', 'type': 'colon', 'children': []},{'id': '53', 'type': 'colon', 'children': []},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'}
def sortedbyAge(self): ''' Sorting the pop. base of the age ''' ageAll = numpy.zeros(self.length) for i in range(self.length): ageAll[i] = self.Ind[i].age ageSorted = ageAll.argsort() return ageSorted[::-1]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'upcoming_releases'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '6', 'type': 'block', 'children': ['7', '11', '19', '36', '42', '52', '59']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '10', 'type': 'string', 'children': [], 'value': "'api/v6/releases/'"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '14', 'type': 'binary_operator', 'children': ['15', '18'], 'value': '+'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '17', 'type': 'string', 'children': [], 'value': "'?product__shortname='"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '26'], 'value': '+'},{'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '25', 'type': 'string', 'children': [], 'value': "'&ga_date__gte='"},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'today'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '+'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '41', 'type': 'string', 'children': [], 'value': "'&ordering=shortname_sort'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'releases'},{'id': '45', 'type': 'yield', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'munchify'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'releases'},{'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': 'defer'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'returnValue'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'result'}
def upcoming_releases(self, product): url = 'api/v6/releases/' url = url + '?product__shortname=' + product url = url + '&ga_date__gte=' + date.today().strftime('%Y-%m-%d') url = url + '&ordering=shortname_sort' releases = yield self._get(url) result = munchify(releases) defer.returnValue(result)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'es_field_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fld_name'},{'id': '5', 'type': 'block', 'children': ['6', '15', '35']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'fld_name'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': '"."'},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'},{'id': '17', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '20', 'type': 'unary_operator', 'children': ['21'], 'value': '-'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '29']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '27', 'type': 'unary_operator', 'children': ['28'], 'value': '-'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '+'},{'id': '30', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"."'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'parts'}
def es_field_sort(fld_name): parts = fld_name.split(".") if "_" not in parts[-1]: parts[-1] = "_" + parts[-1] return ".".join(parts)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_vars'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '21', '40', '44', '106', '129', '337', '349', '356']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "''' load the vars section from a play, accounting for all sorts of variable features\n including loading from yaml files, prompting, and conditional includes of the first\n file found in a list. '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '14']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'if_statement', 'children': ['22', '32']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '29'], 'value': 'not'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '29', 'type': 'list', 'children': ['30', '31'], 'value': '[dict, list]'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'AnsibleError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': '"\'vars\' section must contain only key/value pairs"'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '43', 'type': 'dictionary', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '53', '95']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '52'], 'value': '=='},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '59']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '59', 'type': 'block', 'children': ['60', '77', '89']},{'id': '60', 'type': 'if_statement', 'children': ['61', '69']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '68'], 'value': 'is'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '66', 'type': 'string', 'children': [], 'value': "'items'"},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'AnsibleError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': '"expecting a key-value pair in \'vars\' section"'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'pattern_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'subscript', 'children': ['83', '88']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '106', 'type': 'if_statement', 'children': ['107', '117']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '116'], 'value': '=='},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'extra_vars'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'extra_vars'},{'id': '129', 'type': 'if_statement', 'children': ['130', '138', '265', '328']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '137'], 'value': '=='},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'vars_prompt'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'for_statement', 'children': ['140', '141', '144']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'vars_prompt'},{'id': '144', 'type': 'block', 'children': ['145', '158', '164', '174', '184', '194', '204', '214', '224', '234']},{'id': '145', 'type': 'if_statement', 'children': ['146', '150']},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'in'},{'id': '148', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'AnsibleError'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': '"\'vars_prompt\' item is missing \'name:\'"'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '163', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': '"prompt"'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '183', 'type': 'None', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'private'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': '"private"'},{'id': '193', 'type': 'True', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'confirm'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': '"confirm"'},{'id': '203', 'type': 'False', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'encrypt'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '"encrypt"'},{'id': '213', 'type': 'None', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'salt_size'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': '"salt_size"'},{'id': '223', 'type': 'None', 'children': []},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'string', 'children': [], 'value': '"salt"'},{'id': '233', 'type': 'None', 'children': []},{'id': '234', 'type': 'if_statement', 'children': ['235', '242']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'not'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'extra_vars'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '248', 'type': 'call', 'children': ['249', '256']},{'id': '249', 'type': 'attribute', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'callbacks'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'on_vars_prompt'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259', '260', '261', '262', '263', '264']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'private'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'encrypt'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'confirm'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'salt_size'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'salt'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '265', 'type': 'elif_clause', 'children': ['266', '274']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '273'], 'value': '=='},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'vars_prompt'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'for_statement', 'children': ['276', '279', '286']},{'id': '276', 'type': 'tuple_pattern', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'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': 'vars_prompt'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'block', 'children': ['287', '293']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'prompt_msg'},{'id': '290', 'type': 'binary_operator', 'children': ['291', '292'], 'value': '%'},{'id': '291', 'type': 'string', 'children': [], 'value': '"%s: "'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '293', 'type': 'if_statement', 'children': ['294', '301']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': 'not'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'extra_vars'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '307']},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '307', 'type': 'call', 'children': ['308', '315']},{'id': '308', 'type': 'attribute', 'children': ['309', '314']},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'callbacks'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'on_vars_prompt'},{'id': '315', 'type': 'argument_list', 'children': ['316', '319', '322', '325']},{'id': '316', 'type': 'keyword_argument', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'varname'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'vname'},{'id': '319', 'type': 'keyword_argument', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'private'},{'id': '321', 'type': 'False', 'children': []},{'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'prompt_msg'},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '327', 'type': 'None', 'children': []},{'id': '328', 'type': 'else_clause', 'children': ['329']},{'id': '329', 'type': 'block', 'children': ['330']},{'id': '330', 'type': 'raise_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'AnsibleError'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'string', 'children': [], 'value': '"\'vars_prompt\' section is malformed, see docs"'},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'assignment', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '340', 'type': 'call', 'children': ['341', '348']},{'id': '341', 'type': 'attribute', 'children': ['342', '347']},{'id': '342', 'type': 'attribute', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'playbook'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'extra_vars'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '348', 'type': 'argument_list', 'children': []},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '356', 'type': 'return_statement', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'results'}
def _get_vars(self): ''' load the vars section from a play, accounting for all sorts of variable features including loading from yaml files, prompting, and conditional includes of the first file found in a list. ''' if self.vars is None: self.vars = {} if type(self.vars) not in [dict, list]: raise errors.AnsibleError("'vars' section must contain only key/value pairs") vars = {} if type(self.vars) == list: for item in self.vars: if getattr(item, 'items', None) is None: raise errors.AnsibleError("expecting a key-value pair in 'vars' section") k, v = item.items()[0] vars[k] = v else: vars.update(self.vars) if type(self.playbook.extra_vars) == dict: vars.update(self.playbook.extra_vars) if type(self.vars_prompt) == list: for var in self.vars_prompt: if not 'name' in var: raise errors.AnsibleError("'vars_prompt' item is missing 'name:'") vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) private = var.get("private", True) confirm = var.get("confirm", False) encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) if vname not in self.playbook.extra_vars: vars[vname] = self.playbook.callbacks.on_vars_prompt ( vname, private, prompt, encrypt, confirm, salt_size, salt, default ) elif type(self.vars_prompt) == dict: for (vname, prompt) in self.vars_prompt.iteritems(): prompt_msg = "%s: " % prompt if vname not in self.playbook.extra_vars: vars[vname] = self.playbook.callbacks.on_vars_prompt( varname=vname, private=False, prompt=prompt_msg, default=None ) else: raise errors.AnsibleError("'vars_prompt' section is malformed, see docs") results = self.playbook.extra_vars.copy() results.update(vars) return results
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_refs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_type'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '22', '32', '43']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '12', 'type': 'string', 'children': [], 'value': '"/refs"'},{'id': '13', 'type': 'if_statement', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ref_type'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'augmented_assignment', 'children': ['18', '19'], 'value': '+='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '+'},{'id': '20', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ref_type'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_request'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'profile'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '40']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'prepare'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'result'}
def list_refs(profile, ref_type=None): resource = "/refs" if ref_type: resource += "/" + ref_type data = api.get_request(profile, resource) result = [prepare(x) for x in data] return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fieldname'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '8', 'type': 'lambda', 'children': ['9', '11']},{'id': '9', 'type': 'lambda_parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '45', '84', '93', '114']},{'id': '19', 'type': 'try_statement', 'children': ['20', '35']},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'field_index'},{'id': '24', 'type': 'call', 'children': ['25', '33']},{'id': '25', 'type': 'attribute', 'children': ['26', '32']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fieldname'},{'id': '35', 'type': 'except_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'raise_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'},{'id': '43', 'type': 'string', 'children': [], 'value': '"Sorting on a field that doesn\'t exist: `%s`"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'fieldname'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data_cols'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'izip'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'list_splat', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '54', 'type': 'argument_list', 'children': ['55', '70', '81']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'izip'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'list_splat', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '65']},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '__data'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '72', 'type': 'lambda', 'children': ['73', '75']},{'id': '73', 'type': 'lambda_parameters', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'field_index'},{'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target_table'},{'id': '87', 'type': 'conditional_expression', 'children': ['88', '89', '90'], 'value': 'if'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'DataTable'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'for_statement', 'children': ['94', '97', '104']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'data_col'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'izip'},{'id': '99', 'type': 'argument_list', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'data_cols'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'target_table'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'data_col'},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'target_table'}
def sort(self, fieldname, key=lambda x: x, desc=False, inplace=False): try: field_index = tuple(self.fields).index(fieldname) except ValueError: raise ValueError("Sorting on a field that doesn't exist: `%s`" % fieldname) data_cols = izip(*sorted(izip(*[self.__data[field] for field in self.fields]), key=lambda row: key(row[field_index]), reverse=desc)) target_table = self if inplace else DataTable() for field, data_col in izip(self.fields, data_cols): target_table[field] = list(data_col) return target_table
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersectingIntervalIterator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '7', 'type': 'block', 'children': ['8', '18', '32']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'intersectingInterval'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'end'},{'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': 'items'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'lambda', 'children': ['27', '29']},{'id': '27', 'type': 'lambda_parameters', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'yield', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'}
def intersectingIntervalIterator(self, start, end): items = self.intersectingInterval(start, end) items.sort(key=lambda x: x.start) for item in items: yield item
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sanitize_usecols'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '5', 'type': 'block', 'children': ['6', '13', '63', '67', '128', '138', '144']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'try_statement', 'children': ['14', '38']},{'id': '14', 'type': 'block', 'children': ['15', '24']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'pats'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "','"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'pats'},{'id': '27', 'type': 'list_comprehension', 'children': ['28', '33', '36']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pats'},{'id': '36', 'type': 'if_clause', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '38', 'type': 'except_clause', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '40', 'type': 'block', 'children': ['41', '52', '58']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '49']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'usecols'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '66', 'type': 'list', 'children': [], 'value': '[]'},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pats'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'if_statement', 'children': ['72', '75', '115']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'},{'id': '73', 'type': 'string', 'children': [], 'value': "':'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '75', 'type': 'block', 'children': ['76', '87', '97', '107']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "':'"},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'letter2num'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'zbase'},{'id': '96', 'type': 'True', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'letter2num'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'zbase'},{'id': '106', 'type': 'False', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'augmented_assignment', 'children': ['109', '110'], 'value': '+='},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '120', 'type': 'list', 'children': ['121'], 'value': '[letter2num(pat, zbase=True)]'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'letter2num'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'zbase'},{'id': '127', 'type': 'True', 'children': []},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cols'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'cols'}
def _sanitize_usecols(usecols): if usecols is None: return None try: pats = usecols.split(',') pats = [p.strip() for p in pats if p] except AttributeError: usecols = [int(c) for c in usecols] usecols.sort() return tuple(usecols) cols = [] for pat in pats: if ':' in pat: c1, c2 = pat.split(':') n1 = letter2num(c1, zbase=True) n2 = letter2num(c2, zbase=False) cols += range(n1, n2) else: cols += [letter2num(pat, zbase=True)] cols = list(set(cols)) cols.sort() return tuple(cols)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'binary_search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '25', '34', '62']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '16', 'type': 'conditional_expression', 'children': ['17', '18', '21'], 'value': 'if'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '33'], 'value': '//'},{'id': '29', 'type': '()', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '+'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '33', 'type': 'integer', 'children': [], 'value': '2'},{'id': '34', 'type': 'if_statement', 'children': ['35', '58']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '53'], 'value': 'or'},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '47'], 'value': 'or'},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'or'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '40', 'type': 'integer', 'children': [], 'value': '2'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '>'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'hi'},{'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': 'data'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '>'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'return_statement', 'children': ['60']},{'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '-'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'if_statement', 'children': ['63', '68', '81', '103']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '>'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'binary_search'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75', '78']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '81', 'type': 'elif_clause', 'children': ['82', '87']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': '<'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'binary_search'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94', '100']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lo'},{'id': '96', 'type': '()', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'hi'},{'id': '103', 'type': 'elif_clause', 'children': ['104', '109']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mid'}
def binary_search(data, target, lo=0, hi=None): hi = hi if hi is not None else len(data) mid = (lo + hi) // 2 if hi < 2 or hi > len(data) or target > data[-1] or target < data[0]: return -1 if data[mid] > target: return binary_search(data, target, lo=lo, hi=mid) elif data[mid] < target: return binary_search(data, target, lo=(mid + 1), hi=hi) elif data[mid] == target: return mid
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'repr_feature'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_keys'},{'id': '7', 'type': 'integer', 'children': [], 'value': '100'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '10', 'type': 'integer', 'children': [], 'value': '8'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'lexigraphic'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '46', '77']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''\n generate a pretty-printed string for a feature\n Currently implemented:\n * StringCounter\n @max_keys: truncate long counters\n @indent: indent multi-line displays by this many spaces\n @lexigraphic: instead of sorting counters by count (default), sort\n keys lexigraphically\n '''"},{'id': '17', 'type': 'if_statement', 'children': ['18', '25']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '22', 'type': 'tuple', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'try_statement', 'children': ['27', '39']},{'id': '27', 'type': 'block', 'children': ['28', '37']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ustr'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'utf8'"},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ustr'},{'id': '39', 'type': 'except_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '46', 'type': 'if_statement', 'children': ['47', '52', '61', '70']},{'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': 'feature'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'StringCounter'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'repr_stringcounter'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '60']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max_keys'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'lexigraphic'},{'id': '61', 'type': 'elif_clause', 'children': ['62', '67']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '77', 'type': 'assert_statement', 'children': ['78', '79']},{'id': '78', 'type': 'False', 'children': []},{'id': '79', 'type': 'string', 'children': [], 'value': "'internal logic failure, no branch taken'"}
def repr_feature(feature, max_keys=100, indent=8, lexigraphic=False): ''' generate a pretty-printed string for a feature Currently implemented: * StringCounter @max_keys: truncate long counters @indent: indent multi-line displays by this many spaces @lexigraphic: instead of sorting counters by count (default), sort keys lexigraphically ''' if isinstance(feature, (str, bytes)): try: ustr = feature.decode('utf8') return ustr except: return repr(feature) if isinstance(feature, StringCounter): return repr_stringcounter(feature, max_keys, indent, lexigraphic) elif isinstance(feature, unicode): return feature else: return repr(feature) assert False, 'internal logic failure, no branch taken'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_getkey'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '15', '25', '40', '50']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'keys'},{'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': 'values'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'tuple', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'result'}
def _getkey(self, args, kwargs): values = list(args) keys = sorted(list(kwargs)) for key in keys: values.append((key, kwargs[key])) result = hash(tuple(values)) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterator'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '143']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '9', 'type': 'call', 'children': ['10', '17']},{'id': '10', 'type': 'attribute', 'children': ['11', '16']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'SearchableQuerySet'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '27']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_search_terms'},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_search_ordered'},{'id': '27', 'type': 'block', 'children': ['28', '35', '138']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '35', 'type': 'for_statement', 'children': ['36', '39', '43']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '43', 'type': 'block', 'children': ['44', '48', '52', '109', '130']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'related_weights'},{'id': '51', 'type': 'list', 'children': [], 'value': '[]'},{'id': '52', 'type': 'for_statement', 'children': ['53', '56', '63']},{'id': '53', 'type': 'tuple_pattern', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_search_fields'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '76']},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': '"__"'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'related_weights'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '76', 'type': 'for_statement', 'children': ['77', '78', '81']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_search_terms'},{'id': '81', 'type': 'block', 'children': ['82', '91']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'field_value'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'if_statement', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'field_value'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'augmented_assignment', 'children': ['96', '97'], 'value': '+='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '108'], 'value': '*'},{'id': '98', 'type': 'call', 'children': ['99', '106']},{'id': '99', 'type': 'attribute', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'field_value'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '109', 'type': 'if_statement', 'children': ['110', '114']},{'id': '110', 'type': 'boolean_operator', 'children': ['111', '113'], 'value': 'and'},{'id': '111', 'type': 'not_operator', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'related_weights'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '126'], 'value': '/'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'related_weights'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'related_weights'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'result_count'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '143', 'type': 'return_statement', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'results'}
def iterator(self): results = super(SearchableQuerySet, self).iterator() if self._search_terms and not self._search_ordered: results = list(results) for i, result in enumerate(results): count = 0 related_weights = [] for (field, weight) in self._search_fields.items(): if "__" in field: related_weights.append(weight) for term in self._search_terms: field_value = getattr(result, field, None) if field_value: count += field_value.lower().count(term) * weight if not count and related_weights: count = int(sum(related_weights) / len(related_weights)) results[i].result_count = count return iter(results) return results