sequence
stringlengths
1.19k
35k
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_paths_for_status'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '6', 'type': 'block', 'children': ['7', '16']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '13']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11', '12']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'added'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'modified'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'deleted'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_changes_cache'}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'subscript', 'children': ['21', '40']}, {'id': '21', 'type': 'dictionary', 'children': ['22', '28', '34']}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'added'"}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'added'}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'modified'"}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'modified'}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'deleted'"}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'deleted'}
def _get_paths_for_status(self, status): added, modified, deleted = self._changes_cache return sorted({ 'added': list(added), 'modified': list(modified), 'deleted': list(deleted)}[status] )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '22']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'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': '_list'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '20']}; {'id': '18', 'type': 'list_splat', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '20', 'type': 'dictionary_splat', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '26', '32']}, {'id': '23', 'type': 'pattern_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'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': '_list'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '40']}, {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_dict'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}
def sort(self, *args, **kwargs): self._list.sort(*args, **kwargs) for index, value in enumerate(self._list): self._dict[value] = index
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '24', '28', '32', '100', '112']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '21'], 'value': 'or'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'found_indices'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '35', '61']}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'for_statement', 'children': ['37', '40', '46']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'card'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'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': 'cards'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'check_term'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'card'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'term'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'found_indices'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'for_statement', 'children': ['64', '67', '73']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'card'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78', '97']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '<'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'if_statement', 'children': ['80', '85']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'check_term'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'card'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'term'}, {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'found_indices'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'augmented_assignment', 'children': ['95', '96'], 'value': '+='}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'break_statement', 'children': []}; {'id': '100', 'type': 'if_statement', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'found_indices'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort_card_indices'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110', '111']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'found_indices'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'found_indices'}
def find(self, term, limit=0, sort=False, ranks=None): ranks = ranks or self.ranks found_indices = [] count = 0 if not limit: for i, card in enumerate(self.cards): if check_term(card, term): found_indices.append(i) else: for i, card in enumerate(self.cards): if count < limit: if check_term(card, term): found_indices.append(i) count += 1 else: break if sort: found_indices = sort_card_indices(self, found_indices, ranks) return found_indices
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'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': 'limit'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '24', '28', '177', '188']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '21'], 'value': 'or'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '27', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '28', 'type': 'try_statement', 'children': ['29', '83']}, {'id': '29', 'type': 'block', 'children': ['30', '42', '62']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'find_list'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'terms'}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '51', '54']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '54', 'type': 'if_clause', 'children': ['55']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '61'], 'value': 'not'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'got_cards'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '79']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '79', 'type': 'if_clause', 'children': ['80']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'not'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '83', 'type': 'except_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85', '89', '156']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '88', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'terms'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'try_statement', 'children': ['94', '122']}; {'id': '94', 'type': 'block', 'children': ['95', '103']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'card'}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'not'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'card'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '107', 'type': 'block', 'children': ['108', '115']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'got_cards'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'card'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '122', 'type': 'except_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124', '136']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'augmented_assignment', 'children': ['126', '127'], 'value': '+='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '139', 'type': 'list_comprehension', 'children': ['140', '145', '148']}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '148', 'type': 'if_clause', 'children': ['149']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '155'], 'value': 'not'}; {'id': '150', 'type': 'subscript', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'got_cards'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '161', 'type': 'list_comprehension', 'children': ['162', '163', '173']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '163', 'type': 'for_in_clause', 'children': ['164', '167']}; {'id': '164', 'type': 'pattern_list', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '173', 'type': 'if_clause', 'children': ['174']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'not'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sort_cards'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'got_cards'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '188', 'type': 'return_statement', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'got_cards'}
def get_list(self, terms, limit=0, sort=False, ranks=None): ranks = ranks or self.ranks got_cards = [] try: indices = self.find_list(terms, limit=limit) got_cards = [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] except: indices = [] for item in terms: try: card = self.cards[item] if card not in got_cards: got_cards.append(card) indices.append(item) except: indices += self.find(item, limit=limit) got_cards += [self.cards[i] for i in indices if self.cards[i] not in got_cards] self.cards = [v for i, v in enumerate(self.cards) if i not in indices] if sort: got_cards = sort_cards(got_cards, ranks) return got_cards
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_sorted'}, {'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': 'ranks'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '17']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'check_sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}
def is_sorted(self, ranks=None): ranks = ranks or self.ranks return check_sorted(self, ranks)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'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': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '17']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_cards'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'cards'}
def sort(self, ranks=None): ranks = ranks or self.ranks self.cards = sort_cards(self.cards, ranks)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'canonical_headers'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'headers_to_sign'}; {'id': '6', 'type': 'block', 'children': ['7', '33', '39']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '30']}, {'id': '11', 'type': 'binary_operator', 'children': ['12', '13'], 'value': '%'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'%s:%s'"}, {'id': '13', 'type': 'tuple', 'children': ['14', '23']}; {'id': '14', 'type': 'call', 'children': ['15', '22']}, {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'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': 'headers_to_sign'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'headers_to_sign'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'l'}
def canonical_headers(self, headers_to_sign): l = ['%s:%s'%(n.lower().strip(), headers_to_sign[n].strip()) for n in headers_to_sign] l.sort() return '\n'.join(l)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_cards'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'jokers'}; {'id': '6', 'type': 'False', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'num_jokers'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '33', '48']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'new_deck'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'jokers'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'augmented_assignment', 'children': ['20', '21'], 'value': '+='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'new_deck'}, {'id': '21', 'type': 'list_comprehension', 'children': ['22', '27']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Card'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'string', 'children': [], 'value': '"Joker"'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'xrange'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'num_jokers'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'augmented_assignment', 'children': ['35', '36'], 'value': '+='}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'new_deck'}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '42', '45']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Card'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'suit'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'VALUES'}, {'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'suit'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'SUITS'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'new_deck'}
def build_cards(jokers=False, num_jokers=0): new_deck = [] if jokers: new_deck += [Card("Joker", None) for i in xrange(num_jokers)] new_deck += [Card(value, suit) for value in VALUES for suit in SUITS] return new_deck
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '23']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_RANKS'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted_cards'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_cards'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '37', '40']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '28'], 'value': 'or'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_cards'}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '36'], 'value': '=='}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '31', 'type': 'slice', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'colon', 'children': []}, {'id': '33', 'type': 'colon', 'children': []}; {'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted_cards'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'False', 'children': []}
def check_sorted(cards, ranks=None): ranks = ranks or DEFAULT_RANKS sorted_cards = sort_cards(cards, ranks) if cards == sorted_cards or cards[::-1] == sorted_cards: return True else: return False
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_card_indices'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '54', '83']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '15'], 'value': 'or'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_RANKS'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '23']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"suits"'}, {'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': 'indices'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'lambda', 'children': ['34', '36']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'conditional_expression', 'children': ['37', '46', '53'], 'value': 'if'}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"suits"'}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'suit'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '52'], 'value': '!='}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'suit'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '61']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"values"'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '71', 'type': 'lambda', 'children': ['72', '74']}; {'id': '72', 'type': 'lambda_parameters', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '74', 'type': 'subscript', 'children': ['75', '78']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '77', 'type': 'string', 'children': [], 'value': '"values"'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '83', 'type': 'return_statement', 'children': ['84']}
def sort_card_indices(cards, indices, ranks=None): ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): indices = sorted( indices, key=lambda x: ranks["suits"][cards[x].suit] if cards[x].suit != None else 0 ) if ranks.get("values"): indices = sorted( indices, key=lambda x: ranks["values"][cards[x].value] ) return indices
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_cards'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cards'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '49', '76']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_RANKS'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"suits"'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'conditional_expression', 'children': ['36', '43', '48'], 'value': 'if'}; {'id': '36', 'type': 'subscript', 'children': ['37', '40']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"suits"'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'suit'}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '!='}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'suit'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '56']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ranks'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"values"'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'cards'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '66', 'type': 'lambda', 'children': ['67', '69']}, {'id': '67', 'type': 'lambda_parameters', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ranks'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"values"'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cards'}
def sort_cards(cards, ranks=None): ranks = ranks or DEFAULT_RANKS if ranks.get("suits"): cards = sorted( cards, key=lambda x: ranks["suits"][x.suit] if x.suit != None else 0 ) if ranks.get("values"): cards = sorted( cards, key=lambda x: ranks["values"][x.value] ) return cards
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'key'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '32', '54', '91', '115']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"Return the sort key for the given frame."'}, {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'keytuple'}, {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'primary'}, {'id': '13', 'type': 'block', 'children': ['14', '25']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '20']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': 'is'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'frameno'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'tuple', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'primary'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'tuple', 'children': ['27', '28', '29']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'primary'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'frameno'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '41']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '38'], 'value': 'in'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'frame_keys'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'keytuple'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'frame_keys'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '74']}, {'id': '55', 'type': 'boolean_operator', 'children': ['56', '62'], 'value': 'and'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_in_version'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '71'], 'value': 'in'}, {'id': '63', 'type': 'subscript', 'children': ['64', '70']}; {'id': '64', 'type': 'attribute', 'children': ['65', '69']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'frame_keys'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'keytuple'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'subscript', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'frame_keys'}, {'id': '83', 'type': 'subscript', 'children': ['84', '90']}; {'id': '84', 'type': 'attribute', 'children': ['85', '89']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'for_statement', 'children': ['92', '95', '98']}; {'id': '92', 'type': 'tuple_pattern', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 're_keys'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '109']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'frameid'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'keytuple'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'keytuple'}; {'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': 'unknown_key'}
def key(self, frame): "Return the sort key for the given frame." def keytuple(primary): if frame.frameno is None: return (primary, 1) return (primary, 0, frame.frameno) if type(frame) in self.frame_keys: return keytuple(self.frame_keys[type(frame)]) if frame._in_version(2) and type(frame).__bases__[0] in self.frame_keys: return keytuple(self.frame_keys[type(frame).__bases__[0]]) for (pattern, key) in self.re_keys: if re.match(pattern, frame.frameid): return keytuple(key) return keytuple(self.unknown_key)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'frames'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'orig_order'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '54', '58', '83', '116', '125']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '26', '48']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': '_normalize_key'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '37']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '36'], 'value': '=='}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_frames'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'KeyError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'}, {'id': '43', 'type': 'string', 'children': [], 'value': '"Key not found: "'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_frames'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'frames'}, {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '67']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'frameid'}; {'id': '60', 'type': 'call', 'children': ['61', '66']}, {'id': '61', 'type': 'attribute', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_frames'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '75']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_frames'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'frameid'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '85', '106']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'orig_order'}, {'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': 'key'}, {'id': '89', 'type': 'parenthesized_expression', 'children': ['90'], 'value': '()'}; {'id': '90', 'type': 'lambda', 'children': ['91', '93']}, {'id': '91', 'type': 'lambda_parameters', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'frame'}, {'id': '93', 'type': 'conditional_expression', 'children': ['94', '99', '104'], 'value': 'if'}; {'id': '94', 'type': 'tuple', 'children': ['95', '96']}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'frameno'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': 'is'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'frame'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'frameno'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'tuple', 'children': ['105']}, {'id': '105', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'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': 'key'}, {'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': 'frame_order'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'frames'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '125', 'type': 'return_statement', 'children': ['126']}
def frames(self, key=None, orig_order=False): if key is not None: key = self._normalize_key(key) if len(self._frames[key]) == 0: raise KeyError("Key not found: " + repr(key)) return self._frames[key] frames = [] for frameid in self._frames.keys(): for frame in self._frames[frameid]: frames.append(frame) if orig_order: key = (lambda frame: (0, frame.frameno) if frame.frameno is not None else (1,)) else: key = self.frame_order.key frames.sort(key=key) return frames
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'detach'}, {'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': 'force'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '26', '30', '43']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'instance_id'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'attach_data'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'instance_id'}, {'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': 'attach_data'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'instance_id'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'device'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'attach_data'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'device'}; {'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': 'attach_data'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'device'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '50']}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'detach_volume'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '55', '56']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'instance_id'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'device'}
def detach(self, force=False): instance_id = None if self.attach_data: instance_id = self.attach_data.instance_id device = None if self.attach_data: device = self.attach_data.device return self.connection.detach_volume(self.id, instance_id, device, force)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_node_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'outer_list'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"zone"'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '35', '115', '119', '123', '143']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'raw_dict'}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'inner_list'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'outer_list'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'inner_list'}; {'id': '24', 'type': 'block', 'children': ['25', '31']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'raw_dict'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'augmented_assignment', 'children': ['33', '34'], 'value': '+='}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39', '74']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"name"'}, {'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': 'srt_dict'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '54']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'raw_dict'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'lambda', 'children': ['57', '59']}, {'id': '57', 'type': 'lambda_parameters', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '59', 'type': 'tuple', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cloud'}, {'id': '65', 'type': 'call', 'children': ['66', '73']}; {'id': '66', 'type': 'attribute', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'else_clause', 'children': ['75']}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'srt_dict'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '90']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'raw_dict'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'lambda', 'children': ['93', '95']}, {'id': '93', 'type': 'lambda_parameters', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '95', 'type': 'tuple', 'children': ['96', '101', '106']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cloud'}, {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'zone'}; {'id': '106', 'type': 'call', 'children': ['107', '114']}, {'id': '107', 'type': 'attribute', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'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': 'x'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'node_dict'}; {'id': '122', 'type': 'dictionary', 'children': []}, {'id': '123', 'type': 'for_statement', 'children': ['124', '127', '132']}; {'id': '124', 'type': 'pattern_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'srt_dict'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'block', 'children': ['133', '139']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'node_dict'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '143', 'type': 'return_statement', 'children': ['144']}
def make_node_dict(outer_list, sort="zone"): raw_dict = {} x = 1 for inner_list in outer_list: for node in inner_list: raw_dict[x] = node x += 1 if sort == "name": srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].name.lower()))) else: srt_dict = OrderedDict(sorted(raw_dict.items(), key=lambda k: (k[1].cloud, k[1].zone, k[1].name.lower()))) x = 1 node_dict = {} for i, v in srt_dict.items(): node_dict[x] = v x += 1 return node_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'crack'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fitness_functions'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ntrials'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'nswaps'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '3000'}, {'id': '13', 'type': 'block', 'children': ['14', '28', '99', '134', '151']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22']}, {'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'or'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '<='}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ntrials'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '<='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'nswaps'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"ntrials and nswaps must be positive integers"'}; {'id': '28', 'type': 'function_definition', 'children': ['29', '30', '32']}, {'id': '29', 'type': 'function_name', 'children': [], 'value': 'next_node_inner_climb'}; {'id': '30', 'type': 'parameters', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '32', 'type': 'block', 'children': ['33', '51', '67', '75', '84']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}, {'id': '35', 'type': 'pattern_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '50']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '60']}, {'id': '53', 'type': 'pattern_list', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '60', 'type': 'expression_list', 'children': ['61', '64']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'plaintext'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'decrypt'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_score'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'plaintext'}; {'id': '82', 'type': 'list_splat', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'fitness_functions'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'expression_list', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'node_score'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Decryption'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '98']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'plaintext'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "''"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'node_score'}, {'id': '99', 'type': 'function_definition', 'children': ['100', '101', '103']}; {'id': '100', 'type': 'function_name', 'children': [], 'value': 'next_node_outer_climb'}, {'id': '101', 'type': 'parameters', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '103', 'type': 'block', 'children': ['104', '111', '126']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'shuffle'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '117']}, {'id': '113', 'type': 'pattern_list', 'children': ['114', '115', '116']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'best_score'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'outputs'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'hill_climb'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121', '125']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'nswaps'}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '123', 'type': 'slice', 'children': ['124']}; {'id': '124', 'type': 'colon', 'children': []}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'next_node_inner_climb'}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'expression_list', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'best_score'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'outputs'}; {'id': '132', 'type': 'unary_operator', 'children': ['133'], 'value': '-'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '140']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'decryptions'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'hill_climb'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144', '150']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ntrials'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ascii_uppercase'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'next_node_outer_climb'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'decryptions'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def crack(ciphertext, *fitness_functions, ntrials=30, nswaps=3000): if ntrials <= 0 or nswaps <= 0: raise ValueError("ntrials and nswaps must be positive integers") def next_node_inner_climb(node): a, b = random.sample(range(len(node)), 2) node[a], node[b] = node[b], node[a] plaintext = decrypt(node, ciphertext) node_score = score(plaintext, *fitness_functions) return node, node_score, Decryption(plaintext, ''.join(node), node_score) def next_node_outer_climb(node): random.shuffle(node) key, best_score, outputs = hill_climb(nswaps, node[:], next_node_inner_climb) return key, best_score, outputs[-1] _, _, decryptions = hill_climb(ntrials, list(string.ascii_uppercase), next_node_outer_climb) return sorted(decryptions, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'key_periods'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'max_key_period'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '21', '64']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '<='}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_key_period'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'raise_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"max_key_period must be a positive integer"'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key_scores'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '37']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '36'], 'value': '+'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'max_key_period'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'block', 'children': ['38', '55']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '-'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ENGLISH_IC'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'index_of_coincidence'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'list_splat', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'split_columns'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'period'}, {'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': 'key_scores'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'tuple', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'list_comprehension', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key_scores'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'lambda', 'children': ['78', '80']}; {'id': '78', 'type': 'lambda_parameters', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'}
def key_periods(ciphertext, max_key_period): if max_key_period <= 0: raise ValueError("max_key_period must be a positive integer") key_scores = [] for period in range(1, min(max_key_period, len(ciphertext)) + 1): score = abs(ENGLISH_IC - index_of_coincidence(*split_columns(ciphertext, period))) key_scores.append((period, score)) return [p[0] for p in sorted(key_scores, key=lambda x: x[1])]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'crack'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fitness_functions'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'min_key'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'max_key'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '26'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'shift_function'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'shift_case_english'}; {'id': '16', 'type': 'block', 'children': ['17', '27', '31', '67']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '>='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'min_key'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'max_key'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"min_key cannot exceed max_key"'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'decryptions'}; {'id': '30', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '38']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'min_key'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'max_key'}; {'id': '38', 'type': 'block', 'children': ['39', '50']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'plaintext'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'decrypt'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ciphertext'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shift_function'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'shift_function'}; {'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': 'decryptions'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Decryption'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'plaintext'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'plaintext'}, {'id': '65', 'type': 'list_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fitness_functions'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'decryptions'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def crack(ciphertext, *fitness_functions, min_key=0, max_key=26, shift_function=shift_case_english): if min_key >= max_key: raise ValueError("min_key cannot exceed max_key") decryptions = [] for key in range(min_key, max_key): plaintext = decrypt(key, ciphertext, shift_function=shift_function) decryptions.append(Decryption(plaintext, key, score(plaintext, *fitness_functions))) return sorted(decryptions, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_limit'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '20', '30']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'convert'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '17']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"sort_limit"'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'to_int'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '25']}, {'id': '21', 'type': 'parenthesized_expression', 'children': ['22'], 'value': '()'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '<'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'limit'}
def get_sort_limit(): limit = _.convert(get("sort_limit"), _.to_int) if (limit < 1): limit = None return limit
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_on'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'allowed_indexes'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8', '15', '36']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"sort_on"'}, {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '18'], 'value': 'and'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'allowed_indexes'}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'not'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'allowed_indexes'}, {'id': '21', 'type': 'block', 'children': ['22', '34']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"Index \'{}\' is not in allowed_indexes"'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_on'}
def get_sort_on(allowed_indexes=None): sort_on = get("sort_on") if allowed_indexes and sort_on not in allowed_indexes: logger.warn("Index '{}' is not in allowed_indexes".format(sort_on)) return None return sort_on
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '25', '49', '65']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19']}; {'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': 'thing'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', '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': 'thing'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '33']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'thing'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'StringTypes'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '41']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'thing'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"["'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'literal_eval'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '61']}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'parenthesized_expression', 'children': ['52'], 'value': '()'}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '57'], 'value': 'or'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'is_list'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'is_tuple'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'list', 'children': ['64'], 'value': '[thing]'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'thing'}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'thing'}
def to_list(thing): if thing is None: return [] if isinstance(thing, set): return list(thing) if isinstance(thing, types.StringTypes): if thing.startswith("["): return ast.literal_eval(thing) if not (is_list(thing) or is_tuple(thing)): return [thing] return list(thing)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_spec'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '27', '35']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_indexes'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'catalog'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_indexes'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'si'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_sort_on'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'allowed_indexes'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'all_indexes'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'so'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'req'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_sort_order'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'expression_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'si'}
def get_sort_spec(self): all_indexes = self.catalog.get_indexes() si = req.get_sort_on(allowed_indexes=all_indexes) so = req.get_sort_order() return si, so
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'block', 'children': ['8', '10']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''Sort a list of dictionaries by dictionary key'''"}; {'id': '10', 'type': 'return_statement', 'children': ['11']}, {'id': '11', 'type': 'conditional_expression', 'children': ['12', '22', '23'], 'value': 'if'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}
def sort_dict(self, data, key): '''Sort a list of dictionaries by dictionary key''' return sorted(data, key=itemgetter(key)) if data else []
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_drops'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dropin'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '51', '64', '79']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'load_object'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dropin'}; {'id': '14', 'type': 'try_statement', 'children': ['15', '26']}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'drops'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'drops_type'}; {'id': '26', 'type': 'except_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'try_statement', 'children': ['30', '44']}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'drops'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'load_object'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'%s.%s'"}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dropin'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'drops_type'}; {'id': '44', 'type': 'except_clause', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'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': 'drops'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'if_statement', 'children': ['52', '57']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'drops'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'__drops__'"}, {'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': 'drops'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'drops'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '__drops__'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '69']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'drops'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'drops'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'drops'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'boolean_operator', 'children': ['81', '82'], 'value': 'or'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'drops'}
def load_drops(self, dropin): obj = load_object(dropin) try: drops = getattr(obj, self.drops_type) except AttributeError: try: drops = load_object('%s.%s' % (dropin, self.drops_type)) except ImportError: drops = None if hasattr(drops, '__drops__'): drops = drops.__drops__ if callable(drops): drops = drops(self.app) return drops or []
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr_or_key'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'asc'"}, {'id': '9', 'type': 'block', 'children': ['10', '49', '69', '79']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '19', '26', '42']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '13', 'type': 'tuple', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'gtk'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'SORT_ASCENDING'}, {'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': 'direction'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'gtk'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'SORT_ASCENDING'}; {'id': '26', 'type': 'elif_clause', 'children': ['27', '35']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '29', 'type': 'tuple', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'gtk'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'SORT_DESCENDING'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'gtk'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'SORT_DESCENDING'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'unrecognised direction'"}, {'id': '49', 'type': 'if_statement', 'children': ['50', '54', '61']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'attr_or_key'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort_func'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_key_sort_func'}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sort_func'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_attr_sort_func'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '76']}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'set_default_sort_func'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort_func'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'attr_or_key'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '86']}, {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'set_sort_column_id'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '89']}, {'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'direction'}
def sort_by(self, attr_or_key, direction='asc'): if direction in ('+', 'asc', gtk.SORT_ASCENDING): direction = gtk.SORT_ASCENDING elif direction in ('-', 'desc', gtk.SORT_DESCENDING): direction = gtk.SORT_DESCENDING else: raise AttributeError('unrecognised direction') if callable(attr_or_key): sort_func = self._key_sort_func else: sort_func = self._attr_sort_func self.model.set_default_sort_func(sort_func, attr_or_key) self.model.set_sort_column_id(-1, direction)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '28', '43', '64']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'file_path'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '20']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'file_type'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'splitext'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filepath'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '35']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'file_name'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '43', 'type': 'with_statement', 'children': ['44', '53']}; {'id': '44', 'type': 'with_clause', 'children': ['45']}, {'id': '45', 'type': 'with_item', 'children': ['46']}; {'id': '46', 'type': 'as_pattern', 'children': ['47', '51']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'filepath'}, {'id': '51', 'type': 'as_pattern_target', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ffile'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'file_content'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ffile'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'readlines'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'parenthesized_expression', 'children': ['66'], 'value': '()'}; {'id': '66', 'type': 'call', 'children': ['67', '74']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_load_funcs'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'file_type'}
def load_file(self, filepath): self.file_path = filepath _, self.file_type = os.path.splitext(filepath) _, self.file_name = os.path.split(filepath) with open(filepath) as ffile: self.file_content = ffile.readlines() return (self._load_funcs[self.file_type]())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'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': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'duplicates'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pretty'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'dictionary_splat_pattern', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '25', 'type': 'block', 'children': ['26', '35', '46', '59', '68', '72', '235', '253']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'not'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'href'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'href'"}, {'id': '45', 'type': 'True', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_soup'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'findAll'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'a'"}, {'id': '57', 'type': 'dictionary_splat', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '71', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '75', 'type': 'block', 'children': ['76', '82', '99', '117', '121', '190', '211', '222']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'build_link'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'anchor'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '82', 'type': 'try_statement', 'children': ['83', '95']}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'build_link'}; {'id': '88', 'type': 'string', 'children': [], 'value': "u'seo'"}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'seoify_hyperlink'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'anchor'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'href'"}, {'id': '95', 'type': 'except_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'pass_statement', 'children': []}, {'id': '99', 'type': 'try_statement', 'children': ['100', '113']}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'build_link'}, {'id': '105', 'type': 'string', 'children': [], 'value': "u'text'"}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'or'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'anchor'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'build_link'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'seo'"}, {'id': '113', 'type': 'except_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'pass_statement', 'children': []}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ignore_link'}; {'id': '120', 'type': 'False', 'children': []}, {'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'nixd'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'for_statement', 'children': ['126', '129', '135']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'nixd'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '140']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'build_link'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'if_statement', 'children': ['142', '163', '178']}; {'id': '142', 'type': 'parenthesized_expression', 'children': ['143'], 'value': '()'}, {'id': '143', 'type': 'boolean_operator', 'children': ['144', '153'], 'value': 'and'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '150']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'build_link'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'Iterable'}, {'id': '153', 'type': 'not_operator', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'build_link'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'for_statement', 'children': ['165', '166', '169']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'build_link'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ignore_link'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'exclude_match'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '178', 'type': 'else_clause', 'children': ['179']}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ignore_link'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'exclude_match'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'build_link'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '193']}, {'id': '191', 'type': 'not_operator', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'duplicates'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'for_statement', 'children': ['195', '196', '197']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'if_statement', 'children': ['199', '206']}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': '=='}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'href'"}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'anchor'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'href'"}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ignore_link'}; {'id': '210', 'type': 'True', 'children': []}, {'id': '211', 'type': 'if_statement', 'children': ['212', '214']}; {'id': '212', 'type': 'not_operator', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'ignore_link'}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'build_link'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '233']}, {'id': '223', 'type': 'boolean_operator', 'children': ['224', '227'], 'value': 'and'}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'is'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '226', 'type': 'None', 'children': []}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '232'], 'value': '=='}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'break_statement', 'children': []}, {'id': '235', 'type': 'if_statement', 'children': ['236', '239']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': 'is'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '238', 'type': 'None', 'children': []}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '245', 'type': 'argument_list', 'children': ['246', '247', '250']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '253', 'type': 'if_statement', 'children': ['254', '255', '274']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'pretty'}, {'id': '255', 'type': 'block', 'children': ['256', '267']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'pp'}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'pprint'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'PrettyPrinter'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'pp'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'pprint'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '274', 'type': 'else_clause', 'children': ['275']}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'return_statement', 'children': ['277']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'links'}
def find(self, limit=None, reverse=False, sort=None, exclude=None, duplicates=True, pretty=False, **filters): if exclude is None: exclude = [] if 'href' not in filters: filters['href'] = True search = self._soup.findAll('a', **filters) if reverse: search.reverse() links = [] for anchor in search: build_link = anchor.attrs try: build_link[u'seo'] = seoify_hyperlink(anchor['href']) except KeyError: pass try: build_link[u'text'] = anchor.string or build_link['seo'] except KeyError: pass ignore_link = False for nixd in exclude: for key, value in six.iteritems(nixd): if key in build_link: if (isinstance(build_link[key], collections.Iterable) and not isinstance(build_link[key], six.string_types)): for item in build_link[key]: ignore_link = exclude_match(value, item) else: ignore_link = exclude_match(value, build_link[key]) if not duplicates: for link in links: if link['href'] == anchor['href']: ignore_link = True if not ignore_link: links.append(build_link) if limit is not None and len(links) == limit: break if sort is not None: links = sorted(links, key=sort, reverse=reverse) if pretty: pp = pprint.PrettyPrinter(indent=4) return pp.pprint(links) else: return links
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__draw_cmp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj1'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'obj2'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16', '19', '31']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '>'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj1'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'draw_order'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj2'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'draw_order'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '19', 'type': 'elif_clause', 'children': ['20', '27']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '<'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'obj1'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'draw_order'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj2'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'draw_order'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'unary_operator', 'children': ['30'], 'value': '-'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'return_statement', 'children': ['34']}
def __draw_cmp(self, obj1, obj2): if obj1.draw_order > obj2.draw_order: return 1 elif obj1.draw_order < obj2.draw_order: return -1 else: return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__up_cmp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj1'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'obj2'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16', '19', '31']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': '>'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj1'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'update_order'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'obj2'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'update_order'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '19', 'type': 'elif_clause', 'children': ['20', '27']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '<'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'obj1'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'update_order'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj2'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'update_order'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'unary_operator', 'children': ['30'], 'value': '-'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'return_statement', 'children': ['34']}
def __up_cmp(self, obj1, obj2): if obj1.update_order > obj2.update_order: return 1 elif obj1.update_order < obj2.update_order: return -1 else: return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'discover'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '6', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'retries'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '21', '25', '51', '58', '191', '202']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'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': 'group'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'239.255.255.250'"}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1900'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'ssdp:urn:schemas-upnp-org:device:MediaRenderer:1'"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '28', 'type': 'call', 'children': ['29', '44']}, {'id': '29', 'type': 'attribute', 'children': ['30', '43']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'\\r\\n'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'list', 'children': ['36', '37', '38', '39', '40', '41', '42'], 'value': '[\'M-SEARCH * HTTP/1.1\',\n \'HOST: {group[0]}:{group[1]}\',\n \'MAN: "ssdp:discover"\',\n \'ST: {st}\',\n \'MX: 1\', \'\', \'\']'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'M-SEARCH * HTTP/1.1'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'HOST: {group[0]}:{group[1]}'"}; {'id': '38', 'type': 'string', 'children': [], 'value': '\'MAN: "ssdp:discover"\''}, {'id': '39', 'type': 'string', 'children': [], 'value': "'ST: {st}'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'MX: 1'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"}; {'id': '42', 'type': 'string', 'children': [], 'value': "''"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'setdefaulttimeout'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '64']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'retries'}; {'id': '64', 'type': 'block', 'children': ['65', '82', '95', '108', '121']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '76', '79']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'AF_INET'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'SOCK_DGRAM'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'IPPROTO_UDP'}; {'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': 'sock'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'setsockopt'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '91', '94']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'SOL_SOCKET'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'SO_REUSEADDR'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'sock'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'setsockopt'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '104', '107']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'IPPROTO_IP'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'IP_MULTICAST_TTL'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sendto'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '120']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '121', 'type': 'while_statement', 'children': ['122', '123']}; {'id': '122', 'type': 'True', 'children': []}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'try_statement', 'children': ['125', '185']}, {'id': '125', 'type': 'block', 'children': ['126', '140']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '129', 'type': 'call', 'children': ['130', '138']}; {'id': '130', 'type': 'attribute', 'children': ['131', '137']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'sock'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'recv'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'integer', 'children': [], 'value': '2048'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '140', 'type': 'for_statement', 'children': ['141', '142', '148']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'\\r\\n'"}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'if_statement', 'children': ['150', '156']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'Location: '"}; {'id': '156', 'type': 'block', 'children': ['157', '172']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '160', 'type': 'call', 'children': ['161', '171']}, {'id': '161', 'type': 'attribute', 'children': ['162', '170']}; {'id': '162', 'type': 'subscript', 'children': ['163', '169']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'if_statement', 'children': ['173', '177']}, {'id': '173', 'type': 'not_operator', 'children': ['174']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'in'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'locations'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '185', 'type': 'except_clause', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'break_statement', 'children': []}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '194', 'type': 'list_comprehension', 'children': ['195', '199']}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'RaumfeldDevice'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '202', 'type': 'return_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '217']}; {'id': '206', 'type': 'list_comprehension', 'children': ['207', '208', '211']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'devices'}, {'id': '211', 'type': 'if_clause', 'children': ['212']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '216'], 'value': '=='}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'device'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'model_description'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'Virtual Media Player'"}, {'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '219', 'type': 'lambda', 'children': ['220', '222']}; {'id': '220', 'type': 'lambda_parameters', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'device'}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'device'}
def discover(timeout=1, retries=1): locations = [] group = ('239.255.255.250', 1900) service = 'ssdp:urn:schemas-upnp-org:device:MediaRenderer:1' message = '\r\n'.join(['M-SEARCH * HTTP/1.1', 'HOST: {group[0]}:{group[1]}', 'MAN: "ssdp:discover"', 'ST: {st}', 'MX: 1', '', '']).format(group=group, st=service) socket.setdefaulttimeout(timeout) for _ in range(retries): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) sock.sendto(message.encode('utf-8'), group) while True: try: response = sock.recv(2048).decode('utf-8') for line in response.split('\r\n'): if line.startswith('Location: '): location = line.split(' ')[1].strip() if not location in locations: locations.append(location) except socket.timeout: break devices = [RaumfeldDevice(location) for location in locations] return sorted([device for device in devices if device.model_description == 'Virtual Media Player'], key=lambda device: device.friendly_name)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_user_trades'}, {'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': 'limit'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '14', 'type': 'block', 'children': ['15', '22', '52']}, {'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': '_log'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'get user trades'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'res'}, {'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': '_rest_client'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'/user_transactions'"}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '37', 'type': 'dictionary', 'children': ['38', '43', '46', '49']}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'book'"}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'limit'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '46', 'type': 'pair', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'conditional_expression', 'children': ['54', '59', '66'], 'value': 'if'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '56', 'type': 'slice', 'children': ['57', '58']}, {'id': '57', 'type': 'colon', 'children': []}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '64', '65'], 'value': '>'}; {'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': 'res'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}
def get_user_trades(self, limit=0, offset=0, sort='desc'): self._log('get user trades') res = self._rest_client.post( endpoint='/user_transactions', payload={ 'book': self.name, 'limit': limit, 'offset': offset, 'sort': sort } ) return res[:limit] if len(res) > limit > 0 else res
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'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': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'try_statement', 'children': ['11', '29']}, {'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': 'df'}, {'id': '17', 'type': 'call', 'children': ['18', '27']}; {'id': '18', 'type': 'attribute', 'children': ['19', '26']}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '29', 'type': 'except_clause', 'children': ['30', '34']}; {'id': '30', 'type': 'as_pattern', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '32', 'type': 'as_pattern_target', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'e'}; {'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': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'}, {'id': '43', 'type': 'string', 'children': [], 'value': '"Can not sort the dataframe from column "'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'col'}
def sort(self, col: str): try: self.df = self.df.copy().sort_values(col) except Exception as e: self.err(e, "Can not sort the dataframe from column " + str(col))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'MachineClass'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'stop_function'}, {'id': '7', 'type': 'lambda', 'children': ['8', '10']}; {'id': '8', 'type': 'lambda_parameters', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '<'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '10000'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'machines'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'survival_rate'}; {'id': '18', 'type': 'float', 'children': [], 'value': '0.05'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'mutation_rate'}, {'id': '21', 'type': 'float', 'children': [], 'value': '0.075'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'silent'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '39', '64', '90', '101', '105', '124', '362']}; {'id': '26', 'type': 'function_definition', 'children': ['27', '28', '30']}, {'id': '27', 'type': 'function_name', 'children': [], 'value': 'make_random'}; {'id': '28', 'type': 'parameters', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'MachineClass'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'randomize'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': 'run_once'}, {'id': '41', 'type': 'parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '43', 'type': 'block', 'children': ['44', '50', '56', '62']}; {'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': 'm'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'setUp'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'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': 'm'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'run'}, {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tearDown'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '64', 'type': 'function_definition', 'children': ['65', '66', '68']}, {'id': '65', 'type': 'function_name', 'children': [], 'value': 'make_offspring'}; {'id': '66', 'type': 'parameters', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'survivors'}; {'id': '68', 'type': 'block', 'children': ['69', '76', '83']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'stochastic_choice'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'survivors'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'stochastic_choice'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'crossover'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'generation'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'make_random'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'xrange'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'machines'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'survivors'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'generation'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '107', '118']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'silent'}, {'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': 'log'}, {'id': '111', 'type': 'lambda', 'children': ['112', '117']}; {'id': '112', 'type': 'lambda_parameters', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '114', 'type': 'default_parameter', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '116', 'type': 'None', 'children': []}, {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'else_clause', 'children': ['119']}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': '_log'}; {'id': '124', 'type': 'try_statement', 'children': ['125', '358']}, {'id': '125', 'type': 'block', 'children': ['126', '130']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'while_statement', 'children': ['131', '137']}, {'id': '131', 'type': 'not_operator', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'stop_function'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'iterations'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '137', 'type': 'block', 'children': ['138', '142', '147', '155', '172', '188', '214', '231', '260', '265', '275', '286', '305']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'augmented_assignment', 'children': ['140', '141'], 'value': '+='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'string', 'children': [], 'value': '"running ... "'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'run_once'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'generation'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '164', 'type': 'lambda', 'children': ['165', '167']}, {'id': '165', 'type': 'lambda_parameters', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'generation'}, {'id': '177', 'type': 'slice', 'children': ['178', '179']}; {'id': '178', 'type': 'colon', 'children': []}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '*'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'survival_rate'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '188', 'type': 'for_statement', 'children': ['189', '190', '191']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'if_statement', 'children': ['193', '201']}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '200'], 'value': '>='}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '50'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '207', 'type': 'subscript', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '211', 'type': 'slice', 'children': ['212', '213']}; {'id': '212', 'type': 'colon', 'children': []}, {'id': '213', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '217', 'type': 'list_comprehension', 'children': ['218', '219', '222']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '219', 'type': 'for_in_clause', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'survivors'}; {'id': '222', 'type': 'if_clause', 'children': ['223']}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '230'], 'value': '>'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '231', 'type': 'if_statement', 'children': ['232', '238']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '237'], 'value': '=='}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'block', 'children': ['239', '244', '255', '259']}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'string', 'children': [], 'value': '"\\nNo survivors, restarting"'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'make_random'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'xrange'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'machines'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '259', 'type': 'continue_statement', 'children': []}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'string', 'children': [], 'value': '"crossover ... "'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'cross'}; {'id': '268', 'type': 'lambda', 'children': ['269', '271']}, {'id': '269', 'type': 'lambda_parameters', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'make_offspring'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'generation'}; {'id': '278', 'type': 'call', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '280', 'type': 'argument_list', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'cross'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'xrange'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'machines'}; {'id': '286', 'type': 'for_statement', 'children': ['287', '288', '289']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'generation'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'if_statement', 'children': ['291', '298']}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '297'], 'value': '>'}; {'id': '292', 'type': 'call', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '296', 'type': 'argument_list', 'children': []}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'mutation_rate'}; {'id': '298', 'type': 'block', 'children': ['299']}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'mutate'}; {'id': '304', 'type': 'argument_list', 'children': []}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'binary_operator', 'children': ['310', '311'], 'value': '%'}; {'id': '310', 'type': 'string', 'children': [], 'value': '"\\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\\n"'}, {'id': '311', 'type': 'tuple', 'children': ['312', '313', '325', '338']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'iterations'}, {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'average'}, {'id': '315', 'type': 'argument_list', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '317', 'type': 'lambda', 'children': ['318', '320']}; {'id': '318', 'type': 'lambda_parameters', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '324', 'type': 'argument_list', 'children': []}, {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'average'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'survivors'}, {'id': '329', 'type': 'lambda', 'children': ['330', '332']}; {'id': '330', 'type': 'lambda_parameters', 'children': ['331']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '332', 'type': 'call', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '340', 'type': 'argument_list', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'survivors'}; {'id': '342', 'type': 'lambda', 'children': ['343', '345']}, {'id': '343', 'type': 'lambda_parameters', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '345', 'type': 'binary_operator', 'children': ['346', '352'], 'value': '+'}; {'id': '346', 'type': 'call', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '352', 'type': 'call', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'return_stack'}; {'id': '358', 'type': 'except_clause', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'KeyboardInterrupt'}; {'id': '360', 'type': 'block', 'children': ['361']}, {'id': '361', 'type': 'pass_statement', 'children': []}; {'id': '362', 'type': 'return_statement', 'children': ['363']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'survivors'}
def iterate(MachineClass, stop_function=lambda iterations: iterations < 10000, machines=1000, survival_rate=0.05, mutation_rate=0.075, silent=False): def make_random(n): return MachineClass().randomize() def run_once(m): m.setUp() m.run() m.tearDown() return m def make_offspring(survivors): a = stochastic_choice(survivors) b = stochastic_choice(survivors) return a.crossover(b) generation = map(make_random, xrange(machines)) survivors = generation if silent: log = lambda s,stream=None: None else: log = _log try: iterations = 0 while not stop_function(iterations, survivors): iterations += 1 log("running ... ") generation = map(run_once, generation) generation = sorted(generation, key=lambda m: m.score()) survivors = generation[:int(survival_rate * len(generation))] for s in survivors: if len(s.code) >= 50: s.code = s.code[:50] survivors = [s for s in survivors if len(s.code)>0] if len(survivors) == 0: log("\nNo survivors, restarting") survivors = map(make_random, xrange(machines)) generation = survivors continue log("crossover ... ") cross = lambda _: make_offspring(survivors) generation = map(cross, xrange(machines)) for m in generation: if random.random() > mutation_rate: m.mutate() log("\rgen %d 1-fitness %.12f avg code len %.2f avg stack len %.2f\n" % (iterations, average(survivors, lambda m: m.score()), average(survivors, lambda m: len(m.code)), average(survivors, lambda m: len(m.stack) + len(m.return_stack)))) except KeyboardInterrupt: pass return survivors
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'count_account'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '28', '32', '61']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'selector'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'domain'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'to_selector'}; {'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': 'cos_list'}; {'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': 'request_list'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'CountAccount'"}; {'id': '24', 'type': 'dictionary', 'children': ['25']}, {'id': '25', 'type': 'pair', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'domain'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'selector'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cos_list'}, {'id': '35', 'type': 'block', 'children': ['36', '45']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'_content'"}, {'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': 'ret'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'tuple', 'children': ['52', '60']}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'zobjects'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ClassOfService'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'from_dict'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ret'}
def count_account(self, domain): selector = domain.to_selector() cos_list = self.request_list('CountAccount', {'domain': selector}) ret = [] for i in cos_list: count = int(i['_content']) ret.append((zobjects.ClassOfService.from_dict(i), count)) return list(ret)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_directory'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '22', '61', '113']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'search_response'}, {'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': 'request'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'SearchDirectory'"}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '25', 'type': 'dictionary', 'children': ['26', '33', '40', '47', '54']}; {'id': '26', 'type': 'pair', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"account"'}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'zobjects'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Account'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'from_dict'}, {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"domain"'}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'zobjects'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Domain'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'from_dict'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': '"dl"'}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'zobjects'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'DistributionList'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'from_dict'}, {'id': '47', 'type': 'pair', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"cos"'}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'zobjects'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'COS'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'from_dict'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"calresource"'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'zobjects'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'CalendarResource'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'from_dict'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '65', '70']}; {'id': '62', 'type': 'pattern_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'obj_type'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'in'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj_type'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'search_response'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '84', '100']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'search_response'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'obj_type'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'obj_type'}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '95']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'search_response'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'obj_type'}; {'id': '100', 'type': 'else_clause', 'children': ['101']}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'obj_type'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'search_response'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'obj_type'}, {'id': '113', 'type': 'return_statement', 'children': ['114']}
def search_directory(self, **kwargs): search_response = self.request('SearchDirectory', kwargs) result = {} items = { "account": zobjects.Account.from_dict, "domain": zobjects.Domain.from_dict, "dl": zobjects.DistributionList.from_dict, "cos": zobjects.COS.from_dict, "calresource": zobjects.CalendarResource.from_dict } for obj_type, func in items.items(): if obj_type in search_response: if isinstance(search_response[obj_type], list): result[obj_type] = [ func(v) for v in search_response[obj_type]] else: result[obj_type] = func(search_response[obj_type]) return result
{'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': 'query'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '22']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '18']}, {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '18', 'type': 'dictionary', 'children': ['19']}, {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'_content'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Search'"}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'content'}
def search(self, query, **kwargs): content = kwargs content['query'] = {'_content': query} return self.request('Search', content)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_call_zincrby'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'list_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '11', 'type': 'block', 'children': ['12', '25']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'indexable'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'list', 'children': ['24'], 'value': '[value]'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_traverse_command'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '33', 'type': 'list_splat', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '35', 'type': 'dictionary_splat', 'children': ['36']}
def _call_zincrby(self, command, value, *args, **kwargs): if self.indexable: self.index([value]) return self._traverse_command(command, value, *args, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_extract_value_from_storage'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '26']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'separator'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'expression_list', 'children': ['28', '36']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'separator'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'parts'}
def _extract_value_from_storage(self, string): parts = string.split(self.separator) pk = parts.pop() return self.separator.join(parts), pk
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_boundaries'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8', '14', '18', '22', '26', '143']}; {'id': '8', 'type': 'assert_statement', 'children': ['9']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'handled_suffixes'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32', '54', '69', '80', '95', '121']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '29', 'type': 'tuple', 'children': ['30', '31']}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'string', 'children': [], 'value': "'eq'"}; {'id': '32', 'type': 'block', 'children': ['33', '43']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'}, {'id': '37', 'type': 'string', 'children': [], 'value': "u'[%s%s'"}; {'id': '38', 'type': 'tuple', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'separator'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '53'], 'value': '+'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '53', 'type': 'string', 'children': [], 'value': "b'\\xff'"}; {'id': '54', 'type': 'elif_clause', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'gt'"}; {'id': '58', 'type': 'block', 'children': ['59', '65']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'}, {'id': '63', 'type': 'string', 'children': [], 'value': "u'(%s'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '69', 'type': 'elif_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'gte'"}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'}; {'id': '78', 'type': 'string', 'children': [], 'value': "u'[%s'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '80', 'type': 'elif_clause', 'children': ['81', '84']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '=='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'lt'"}; {'id': '84', 'type': 'block', 'children': ['85', '91']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'}, {'id': '89', 'type': 'string', 'children': [], 'value': "u'(%s'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '95', 'type': 'elif_clause', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'lte'"}, {'id': '99', 'type': 'block', 'children': ['100', '110']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'}; {'id': '104', 'type': 'string', 'children': [], 'value': "u'[%s%s'"}, {'id': '105', 'type': 'tuple', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'separator'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '120'], 'value': '+'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '120', 'type': 'string', 'children': [], 'value': "b'\\xff'"}, {'id': '121', 'type': 'elif_clause', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'startswith'"}, {'id': '125', 'type': 'block', 'children': ['126', '132']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'}; {'id': '130', 'type': 'string', 'children': [], 'value': "u'[%s'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '142'], 'value': '+'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '142', 'type': 'string', 'children': [], 'value': "b'\\xff'"}, {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'expression_list', 'children': ['145', '146', '147']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'exclude'}
def get_boundaries(self, filter_type, value): assert filter_type in self.handled_suffixes start = '-' end = '+' exclude = None if filter_type in (None, 'eq'): start = u'[%s%s' % (value, self.separator) end = start.encode('utf-8') + b'\xff' elif filter_type == 'gt': start = u'(%s' % value exclude = value elif filter_type == 'gte': start = u'[%s' % value elif filter_type == 'lt': end = u'(%s' % value exclude = value elif filter_type == 'lte': end = u'[%s%s' % (value, self.separator) end = end.encode('utf-8') + b'\xff' elif filter_type == 'startswith': start = u'[%s' % value end = start.encode('utf-8') + b'\xff' return start, end, exclude
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_boundaries'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8', '14', '18', '22', '26', '79']}; {'id': '8', 'type': 'assert_statement', 'children': ['9']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'in'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'handled_suffixes'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'-inf'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'+inf'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32', '39', '50', '59', '70']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '29', 'type': 'tuple', 'children': ['30', '31']}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'string', 'children': [], 'value': "'eq'"}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '39', 'type': 'elif_clause', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'gt'"}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'(%s'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'gte'"}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '59', 'type': 'elif_clause', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'filter_type'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'lt'"}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '%'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'(%s'"}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '70', 'type': 'elif_clause', 'children': ['71', '74']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'filter_type'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'lte'"}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'expression_list', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'exclude'}
def get_boundaries(self, filter_type, value): assert filter_type in self.handled_suffixes start = '-inf' end = '+inf' exclude = None if filter_type in (None, 'eq'): start = end = value elif filter_type == 'gt': start = '(%s' % value elif filter_type == 'gte': start = value elif filter_type == 'lt': end = '(%s' % value elif filter_type == 'lte': end = value return start, end, exclude
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_combine_sets'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'final_set'}, {'id': '7', 'type': 'block', 'children': ['8', '46']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '30']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_has_sortedsets'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '24']}, {'id': '15', 'type': 'attribute', 'children': ['16', '23']}; {'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': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_connection'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'zinterstore'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'final_set'}, {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ExtendedCollectionManager'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_combine_sets'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'final_set'}
def _combine_sets(self, sets, final_set): if self._has_sortedsets: self.cls.get_connection().zinterstore(final_set, list(sets)) else: final_set = super(ExtendedCollectionManager, self)._combine_sets(sets, final_set) return final_set
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_final_redis_call'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '37', '84']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'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': 'cls'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_connection'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'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': '_has_sortedsets'}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'zrange'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'unary_operator', 'children': ['36'], 'value': '-'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '73']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '61', '62'], 'value': 'and'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '50', '51'], 'value': 'and'}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stored_key'}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'sets'"}; {'id': '50', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '60'], 'value': '=='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'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': '_lazy_collection'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'intersects'"}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '62', 'type': 'parenthesized_expression', 'children': ['63'], 'value': '()'}, {'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'or'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '69', 'type': 'dictionary', 'children': ['70']}; {'id': '70', 'type': 'pair', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': "'by'"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'nosort'"}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'lrange'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'final_set'}, {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '93']}; {'id': '86', 'type': 'attribute', 'children': ['87', '92']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ExtendedCollectionManager'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_final_redis_call'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'final_set'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_options'}
def _final_redis_call(self, final_set, sort_options): conn = self.cls.get_connection() if self._has_sortedsets and sort_options is None: return conn.zrange(final_set, 0, -1) if self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1\ and (sort_options is None or sort_options == {'by': 'nosort'}): return conn.lrange(final_set, 0, -1) return super(ExtendedCollectionManager, self)._final_redis_call( final_set, sort_options)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_collection_length'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '60']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_connection'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21', '29']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_has_sortedsets'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'conn'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'zcard'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'final_set'}, {'id': '29', 'type': 'elif_clause', 'children': ['30', '52']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '41', '42'], 'value': 'and'}, {'id': '31', 'type': 'boolean_operator', 'children': ['32', '35'], 'value': 'and'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'stored_key'}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'subscript', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'sets'"}, {'id': '41', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '51'], 'value': '=='}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'intersects'"}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'llen'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '69']}; {'id': '62', 'type': 'attribute', 'children': ['63', '68']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ExtendedCollectionManager'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_collection_length'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}
def _collection_length(self, final_set): conn = self.cls.get_connection() if self._has_sortedsets: return conn.zcard(final_set) elif self.stored_key and not self._lazy_collection['sets']\ and len(self._lazy_collection['intersects']) == 1: return conn.llen(final_set) return super(ExtendedCollectionManager, self)._collection_length(final_set)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_sort_by_score'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '7', 'type': 'block', 'children': ['8', '28', '36', '61', '97']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '13']}; {'id': '10', 'type': 'pattern_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tmp_keys'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_zset_to_keys'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '25']}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'by'"}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'values'}; {'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': 'sort_options'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'by'"}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'%s:*'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '43']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'tuple', 'children': ['39', '40', '41', '42']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'alpha'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'store'"}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '56']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '68']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'try_statement', 'children': ['70', '82', '85']}; {'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': 'pos'}; {'id': '74', 'type': 'call', 'children': ['75', '80']}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'get'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'SORTED_SCORE'}; {'id': '82', 'type': 'except_clause', 'children': ['83']}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'pass_statement', 'children': []}, {'id': '85', 'type': 'else_clause', 'children': ['86']}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '94']}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'get'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'%s:*'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}, {'id': '97', 'type': 'return_statement', 'children': ['98']}; {'id': '98', 'type': 'expression_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}
def _prepare_sort_by_score(self, values, sort_options): base_tmp_key, tmp_keys = self._zset_to_keys( key=self._sort_by_sortedset['by'], values=values, ) sort_options['by'] = '%s:*' % base_tmp_key for key in ('desc', 'alpha', 'get', 'store'): if key in self._sort_by_sortedset: sort_options[key] = self._sort_by_sortedset[key] if sort_options.get('get'): try: pos = sort_options['get'].index(SORTED_SCORE) except: pass else: sort_options['get'][pos] = '%s:*' % base_tmp_key return base_tmp_key, tmp_keys
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_sort_options'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'has_pk'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '45', '112']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '10', 'type': 'call', 'children': ['11', '18']}, {'id': '11', 'type': 'attribute', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ExtendedCollectionManager'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_prepare_sort_options'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'has_pk'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_values'}; {'id': '24', 'type': 'block', 'children': ['25', '33']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'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': 'sort_options'}; {'id': '32', 'type': 'dictionary', 'children': []}, {'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': 'sort_options'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '38', 'type': 'subscript', 'children': ['39', '44']}, {'id': '39', 'type': 'subscript', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_values'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'keys'"}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset_after'}, {'id': '49', 'type': 'block', 'children': ['50', '69', '104']}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '55']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'tuple', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '54', 'type': 'string', 'children': [], 'value': "'store'"}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '62']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'in'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'delete_statement', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '79']}; {'id': '70', 'type': 'boolean_operator', 'children': ['71', '72'], 'value': 'and'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '72', 'type': 'parenthesized_expression', 'children': ['73'], 'value': '()'}, {'id': '73', 'type': 'boolean_operator', 'children': ['74', '76'], 'value': 'or'}; {'id': '74', 'type': 'not_operator', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'has_pk'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_want_score_value'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '82', 'type': 'tuple', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'store'"}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '98']}, {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '107']}, {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'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': 'sort_options'}, {'id': '111', 'type': 'None', 'children': []}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort_options'}
def _prepare_sort_options(self, has_pk): sort_options = super(ExtendedCollectionManager, self)._prepare_sort_options(has_pk) if self._values: if not sort_options: sort_options = {} sort_options['get'] = self._values['fields']['keys'] if self._sort_by_sortedset_after: for key in ('get', 'store'): if key in self._sort_by_sortedset: del self._sort_by_sortedset[key] if sort_options and (not has_pk or self._want_score_value): for key in ('get', 'store'): if key in sort_options: self._sort_by_sortedset[key] = sort_options.pop(key) if not sort_options: sort_options = None return sort_options
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_final_set'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '8', 'type': 'block', 'children': ['9', '64', '81', '119']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'intersects'"}, {'id': '15', 'type': 'block', 'children': ['16', '24', '35']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'colon', 'children': []}, {'id': '23', 'type': 'colon', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'intersects'"}, {'id': '35', 'type': 'if_statement', 'children': ['36', '47']}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '43'], 'value': 'and'}, {'id': '37', 'type': 'not_operator', 'children': ['38']}; {'id': '38', 'type': 'subscript', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_lazy_collection'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'sets'"}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stored_key'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sets'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '63']}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_field'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'pk'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'collection_key'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'keys_to_delete_later'}, {'id': '69', 'type': 'call', 'children': ['70', '77']}; {'id': '70', 'type': 'attribute', 'children': ['71', '76']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ExtendedCollectionManager'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '_get_final_set'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sets'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '87']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '84'], 'value': 'and'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_sort_by_sortedset_before'}, {'id': '87', 'type': 'block', 'children': ['88', '100', '108', '115']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'pattern_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tmp_keys'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_prepare_sort_by_score'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'None', 'children': []}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '103']}, {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'keys_to_delete_later'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'keys_to_delete_later'}, {'id': '107', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'keys_to_delete_later'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'base_tmp_key'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'keys_to_delete_later'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'tmp_keys'}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'expression_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'final_set'}
def _get_final_set(self, sets, pk, sort_options): if self._lazy_collection['intersects']: sets = sets[::] sets.extend(self._lazy_collection['intersects']) if not self._lazy_collection['sets'] and not self.stored_key: sets.append(self.cls.get_field('pk').collection_key) final_set, keys_to_delete_later = super(ExtendedCollectionManager, self)._get_final_set(sets, pk, sort_options) if final_set and self._sort_by_sortedset_before: base_tmp_key, tmp_keys = self._prepare_sort_by_score(None, sort_options) if not keys_to_delete_later: keys_to_delete_later = [] keys_to_delete_later.append(base_tmp_key) keys_to_delete_later += tmp_keys return final_set, keys_to_delete_later
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_sort_options'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'has_pk'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '30', '89', '103']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'if_statement', 'children': ['12', '20']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '18'], 'value': 'and'}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '17'], 'value': 'is'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_sort'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'not_operator', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'has_pk'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'update'}; {'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': '_sort'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'is'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37', '80']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '49', '59']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '44'], 'value': 'and'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'not'}, {'id': '45', 'type': 'string', 'children': [], 'value': "'num'"}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'num'"}, {'id': '57', 'type': 'unary_operator', 'children': ['58'], 'value': '-'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'elif_clause', 'children': ['60', '71']}; {'id': '60', 'type': 'boolean_operator', 'children': ['61', '66'], 'value': 'and'}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'num'"}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '79']}; {'id': '74', 'type': 'subscript', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'sort_options'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_sort_limits'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '98']}; {'id': '90', 'type': 'boolean_operator', 'children': ['91', '93'], 'value': 'and'}, {'id': '91', 'type': 'not_operator', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': 'is'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_sort'}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '102', 'type': 'None', 'children': []}, {'id': '103', 'type': 'return_statement', 'children': ['104']}
def _prepare_sort_options(self, has_pk): sort_options = {} if self._sort is not None and not has_pk: sort_options.update(self._sort) if self._sort_limits is not None: if 'start' in self._sort_limits and 'num' not in self._sort_limits: self._sort_limits['num'] = -1 elif 'num' in self._sort_limits and 'start' not in self._sort_limits: self._sort_limits['start'] = 0 sort_options.update(self._sort_limits) if not sort_options and self._sort is None: sort_options = None return sort_options
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_final_redis_call'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '7', 'type': 'block', 'children': ['8', '18']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'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': 'cls'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_connection'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22', '32']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'conn'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'final_set'}; {'id': '30', 'type': 'dictionary_splat', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '32', 'type': 'else_clause', 'children': ['33']}, {'id': '33', 'type': 'block', 'children': ['34']}; {'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': 'conn'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'smembers'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}
def _final_redis_call(self, final_set, sort_options): conn = self.cls.get_connection() if sort_options is not None: return conn.sort(final_set, **sort_options) else: return conn.smembers(final_set)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query_mongo_sort_decend'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'database_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '8', 'type': 'dictionary', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'skip'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18', '19']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'MONGO_LIMIT'"}, {'id': '19', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'return_keys'}; {'id': '22', 'type': 'tuple', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortkey'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '31', '35', '245']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '30', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '34', 'type': 'dictionary', 'children': []}, {'id': '35', 'type': 'try_statement', 'children': ['36', '189']}; {'id': '36', 'type': 'block', 'children': ['37', '46', '56', '65', '74', '144', '150', '156', '183']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'mongodb_client_url'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'settings'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'MONGODB_CLIENT'"}, {'id': '45', 'type': 'string', 'children': [], 'value': "'mongodb://localhost:27017/'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'mc'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'MongoClient'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mongodb_client_url'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'document_class'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'mc'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'database_name'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'collection_name'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '76', '117']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'return_keys'}; {'id': '76', 'type': 'block', 'children': ['77', '81', '91']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'return_dict'}; {'id': '80', 'type': 'dictionary', 'children': []}, {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'return_keys'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'return_dict'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'mysearchresult'}; {'id': '94', 'type': 'call', 'children': ['95', '114']}, {'id': '95', 'type': 'attribute', 'children': ['96', '113']}; {'id': '96', 'type': 'call', 'children': ['97', '111']}, {'id': '97', 'type': 'attribute', 'children': ['98', '110']}; {'id': '98', 'type': 'call', 'children': ['99', '108']}, {'id': '99', 'type': 'attribute', 'children': ['100', '107']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'return_dict'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sortkey'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'mysearchresult'}; {'id': '122', 'type': 'call', 'children': ['123', '141']}, {'id': '123', 'type': 'attribute', 'children': ['124', '140']}; {'id': '124', 'type': 'call', 'children': ['125', '138']}, {'id': '125', 'type': 'attribute', 'children': ['126', '137']}; {'id': '126', 'type': 'call', 'children': ['127', '135']}, {'id': '127', 'type': 'attribute', 'children': ['128', '134']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'skip'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'skip'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'sortkey'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'code'"}, {'id': '149', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '155']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '155', 'type': 'string', 'children': [], 'value': '"search-results"'}; {'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'mysearchresult'}, {'id': '159', 'type': 'block', 'children': ['160', '172', '176']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '165', 'type': 'call', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '169', 'type': 'string', 'children': [], 'value': "'_id'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '__str__'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'delete_statement', 'children': ['173']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'_id'"}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'response_dict'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'results'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '189', 'type': 'except_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191', '196', '208', '214', '220', '226', '232']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'string', 'children': [], 'value': '"Error reading from Mongo"'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'exc_info'}, {'id': '207', 'type': 'argument_list', 'children': []}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '213']}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'num_results'"}, {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'code'"}, {'id': '219', 'type': 'integer', 'children': [], 'value': '500'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '225', 'type': 'string', 'children': [], 'value': '"Error"'}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'results'"}, {'id': '231', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '237']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'response_dict'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'message'"}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'exc_info'}; {'id': '244', 'type': 'argument_list', 'children': []}, {'id': '245', 'type': 'return_statement', 'children': ['246']}
def query_mongo_sort_decend( database_name, collection_name, query={}, skip=0, limit=getattr( settings, 'MONGO_LIMIT', 200), return_keys=(), sortkey=None): l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(collection_name)] if return_keys: return_dict = {} for k in return_keys: return_dict[k] = 1 mysearchresult = collection.find( query, return_dict).skip(skip).limit(limit).sort( sortkey, DESCENDING) else: mysearchresult = collection.find(query).skip( skip).limit(limit).sort(sortkey, DESCENDING) response_dict['code'] = 200 response_dict['type'] = "search-results" for d in mysearchresult: d['id'] = d['_id'].__str__() del d['_id'] l.append(d) response_dict['results'] = l except: print("Error reading from Mongo") print(str(sys.exc_info())) response_dict['num_results'] = 0 response_dict['code'] = 500 response_dict['type'] = "Error" response_dict['results'] = [] response_dict['message'] = str(sys.exc_info()) return response_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '14', '24', '75']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "''' Break url parameters and turn into sort arguments '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'order_by'"}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '26', 'type': 'block', 'children': ['27', '41']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '33'], 'value': 'is'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49', '64']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '48'], 'value': '=='}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '45', 'type': 'slice', 'children': ['46', '47']}; {'id': '46', 'type': 'colon', 'children': []}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'tuple', 'children': ['57', '62']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '59', 'type': 'slice', 'children': ['60', '61']}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'}, {'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': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'tuple', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'return_statement', 'children': ['76']}
def build_sort(self, **kwargs): ''' Break url parameters and turn into sort arguments ''' sort = [] order = kwargs.get('order_by', None) if order: if type(order) is list: order = order[0] if order[:1] == '-': sort.append((order[1:], -1)) else: sort.append((order, 1)) return sort
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_remotes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'extra_path'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'load_user'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '17', '39']}, {'id': '11', 'type': 'import_from_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'dotted_name', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'getmtime'}, {'id': '17', 'type': 'try_statement', 'children': ['18', '32']}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'find_config_file'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '29']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'REMOTES_FILE'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'extra_path'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'extra_path'}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'load_user'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'load_user'}; {'id': '32', 'type': 'except_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ConfigurationError'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'if_statement', 'children': ['40', '52', '95']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'and'}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}, {'id': '43', 'type': 'None', 'children': []}; {'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': 'exists'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}; {'id': '52', 'type': 'block', 'children': ['53', '59', '66', '80', '93']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'AttrDict'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'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': 'config'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'update_yaml'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '71']}, {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'remotes'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'remotes'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'AttrDict'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'remotes'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'loaded'}, {'id': '87', 'type': 'list', 'children': ['88', '89'], 'value': '[remotes_file, getmtime(remotes_file)]'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'getmtime'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'remotes_file'}, {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '95', 'type': 'else_clause', 'children': ['96']}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'return_statement', 'children': ['98']}
def load_remotes(extra_path=None, load_user=True): from os.path import getmtime try: remotes_file = find_config_file(REMOTES_FILE, extra_path=extra_path, load_user=load_user) except ConfigurationError: remotes_file = None if remotes_file is not None and os.path.exists(remotes_file): config = AttrDict() config.update_yaml(remotes_file) if not 'remotes' in config: config.remotes = AttrDict() config.remotes.loaded = [remotes_file, getmtime(remotes_file)] return config else: return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_previous'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '6', 'type': 'block', 'children': ['7', '14']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '18', '22']}, {'id': '15', 'type': 'pattern_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '22', 'type': 'block', 'children': ['23', '32', '44']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': '=='}, {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '-'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'length'}, {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '=='}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '<'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'current'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47', '48'], 'value': '<='}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'current'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '+'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'current'}
def find_previous(element, l): length = len(l) for index, current in enumerate(l): if length - 1 == index: return current if index == 0: if element < current: return None if current <= element < l[index+1]: return current
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tsort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '30', '38', '42', '102', '110']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'task_dict'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tasks'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'task_dict'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dependencies'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'task_dict'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'while_statement', 'children': ['43', '44']}, {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '65', '70', '77']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'list_comprehension', 'children': ['52', '53', '62']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '53', 'type': 'for_in_clause', 'children': ['54', '57']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'if_clause', 'children': ['63']}, {'id': '63', 'type': 'not_operator', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '68']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'break_statement', 'children': []}; {'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': 'result'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'list_comprehension', 'children': ['84', '89', '98']}; {'id': '84', 'type': 'tuple', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '-'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '89', 'type': 'for_in_clause', 'children': ['90', '93']}; {'id': '90', 'type': 'pattern_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'if_clause', 'children': ['99']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'not'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'raise_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'total ordering not possible (check for circular or missing dependencies)'"}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'result'}
def tsort(self): task_dict = {} for key, task in self.tasks.iteritems(): task_dict[task] = task.dependencies parts = task_dict.copy() result = [] while True: level = set([name for name, deps in parts.iteritems() if not deps]) if not level: break result.append(level) parts = dict([(name, deps - level) for name, deps in parts.iteritems() if name not in level]) if parts: raise ValueError('total ordering not possible (check for circular or missing dependencies)') return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getBounds'}, {'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': 'tzinfo'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '49']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '27', '41']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '23', '24'], 'value': 'and'}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': '>='}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'resolution'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'time'}, {'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': '_time'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}, {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_time'}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'tuple', 'children': ['51', '68']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '60']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fromDatetime'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'time'}; {'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': 'fromDatetime'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_time'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '81']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'fromDatetime'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'resolution'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'fromDatetime'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '90'], 'value': '+'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_time'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}
def getBounds(self, tzinfo=None): if self.resolution >= datetime.timedelta(days=1) \ and tzinfo is not None: time = self._time.replace(tzinfo=tzinfo) else: time = self._time return ( min(self.fromDatetime(time), self.fromDatetime(self._time)), max(self.fromDatetime(time + self.resolution), self.fromDatetime(self._time + self.resolution)) )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_all_migrations'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '10', '14', '22', '26', '72', '87']}, {'id': '5', 'type': 'import_from_statement', 'children': ['6', '8']}; {'id': '6', 'type': 'relative_import', 'children': ['7']}, {'id': '7', 'type': 'import_prefix', 'children': []}; {'id': '8', 'type': 'dotted_name', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'migrations'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'package'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'migrations'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '21'], 'value': '+'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'all_migrations'}, {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '31', '40']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'importer'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ispkg'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pkgutil'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'iter_modules'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'package'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '__path__'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '40', 'type': 'block', 'children': ['41', '63']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'version'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'subscript', 'children': ['48', '62']}; {'id': '48', 'type': 'call', 'children': ['49', '60']}, {'id': '49', 'type': 'attribute', 'children': ['50', '59']}; {'id': '50', 'type': 'subscript', 'children': ['51', '57']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '57', 'type': 'unary_operator', 'children': ['58'], 'value': '-'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'all_migrations'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'tuple', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'modname'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'all_migrations'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'all_migrations'}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '81', 'type': 'lambda', 'children': ['82', '84']}; {'id': '82', 'type': 'lambda_parameters', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'return_statement', 'children': ['88']}
def _get_all_migrations(): from . import migrations package = migrations prefix = package.__name__ + '.' all_migrations = [] for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix): version = int(modname.split('.')[-1].split('_')[0]) all_migrations.append((version, modname)) all_migrations = sorted(all_migrations, key=lambda x: x[0]) return all_migrations
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_genes'}, {'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': 'stable'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '19', '26']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'quicksort'"}, {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'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': 'kind'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'mergesort'"}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_index'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35', '38']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def sort_genes(self, stable=True, inplace=False, ascending=True): kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(kind=kind, inplace=inplace, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_samples'}, {'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': 'stable'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '19', '26']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'quicksort'"}, {'id': '19', 'type': 'if_statement', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'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': 'kind'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'mergesort'"}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort_index'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35', '38', '41']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ascending'}
def sort_samples(self, stable=True, inplace=False, ascending=True): kind = 'quicksort' if stable: kind = 'mergesort' return self.sort_index(axis=1, kind=kind, inplace=inplace, ascending=ascending)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parseColors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'colors'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'defaultColor'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '140', '155', '177']}, {'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': 'if_statement', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'colors'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'colorInfo'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'colors'}, {'id': '17', 'type': 'block', 'children': ['18', '29']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'colorInfo'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '36', '116']}; {'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': 'fields'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '36', 'type': 'block', 'children': ['37', '43', '78', '107']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '43', 'type': 'try_statement', 'children': ['44', '52']}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '52', 'type': 'except_clause', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '54', 'type': 'block', 'children': ['55', '71']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '66']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '65'], 'value': '%'}; {'id': '60', 'type': 'concatenated_string', 'children': ['61', '62', '63', '64']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'--color arguments must be given as space-separated '"}; {'id': '62', 'type': 'string', 'children': [], 'value': '\'pairs of "value color" where the value is a \''}, {'id': '63', 'type': 'string', 'children': [], 'value': "'numeric identity threshold. Your value %r is not '"}; {'id': '64', 'type': 'string', 'children': [], 'value': "'numeric.'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '83']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81', '82'], 'value': '>'}; {'id': '80', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '82', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '83', 'type': 'block', 'children': ['84', '100']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '95']}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '94'], 'value': '%'}, {'id': '89', 'type': 'concatenated_string', 'children': ['90', '91', '92', '93']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'--color arguments must be given as space-separated '"}, {'id': '91', 'type': 'string', 'children': [], 'value': '\'pairs of "value color" where the value is a \''}; {'id': '92', 'type': 'string', 'children': [], 'value': "'numeric identity threshold from 0.0 to 1.0. Your '"}, {'id': '93', 'type': 'string', 'children': [], 'value': "'value %r is not in that range.'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'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': 'sys'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'tuple', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'threshold'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '116', 'type': 'else_clause', 'children': ['117']}, {'id': '117', 'type': 'block', 'children': ['118', '133']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '128']}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '127'], 'value': '%'}, {'id': '123', 'type': 'concatenated_string', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'--color arguments must be given as space-separated '"}, {'id': '125', 'type': 'string', 'children': [], 'value': '\'pairs of "value color". You have given %r, which does \''}; {'id': '126', 'type': 'string', 'children': [], 'value': "'not contain a space.'"}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'colorInfo'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '152']}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '154', 'type': 'True', 'children': []}, {'id': '155', 'type': 'if_statement', 'children': ['156', '167']}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '159'], 'value': 'or'}, {'id': '157', 'type': 'not_operator', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '166'], 'value': '>'}; {'id': '160', 'type': 'subscript', 'children': ['161', '165']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '163', 'type': 'unary_operator', 'children': ['164'], 'value': '-'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}, {'id': '175', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'defaultColor'}, {'id': '177', 'type': 'return_statement', 'children': ['178']}
def parseColors(colors, defaultColor): result = [] if colors: for colorInfo in colors: fields = colorInfo.split(maxsplit=1) if len(fields) == 2: threshold, color = fields try: threshold = float(threshold) except ValueError: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold. Your value %r is not ' 'numeric.' % threshold, file=sys.stderr) sys.exit(1) if 0.0 > threshold > 1.0: print('--color arguments must be given as space-separated ' 'pairs of "value color" where the value is a ' 'numeric identity threshold from 0.0 to 1.0. Your ' 'value %r is not in that range.' % threshold, file=sys.stderr) sys.exit(1) result.append((threshold, color)) else: print('--color arguments must be given as space-separated ' 'pairs of "value color". You have given %r, which does ' 'not contain a space.' % colorInfo, file=sys.stderr) sys.exit(1) result.sort(key=itemgetter(0), reverse=True) if not result or result[-1][0] > 0.0: result.append((0.0, defaultColor)) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bisect_index'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '33']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bisect'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bisect_left'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '30']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '25'], 'value': 'and'}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '!='}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'a'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '29'], 'value': '=='}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'raise_statement', 'children': ['34']}
def bisect_index(a, x): i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i raise ValueError
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'writeSampleIndex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '42']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '15', 'type': 'generator_expression', 'children': ['16', '21']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '%'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'%d %s'"}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'for_in_clause', 'children': ['22', '25']}; {'id': '22', 'type': 'tuple_pattern', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '27', 'type': 'generator_expression', 'children': ['28', '31']}; {'id': '28', 'type': 'tuple', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '35']}; {'id': '32', 'type': 'tuple_pattern', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_samples'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'file'}
def writeSampleIndex(self, fp): print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._samples.items()) ), file=fp)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'writePathogenIndex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '42']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '15', 'type': 'generator_expression', 'children': ['16', '21']}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '%'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'%d %s'"}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'for_in_clause', 'children': ['22', '25']}; {'id': '22', 'type': 'tuple_pattern', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '27', 'type': 'generator_expression', 'children': ['28', '31']}; {'id': '28', 'type': 'tuple', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '35']}; {'id': '32', 'type': 'tuple_pattern', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_pathogens'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'file'}
def writePathogenIndex(self, fp): print('\n'.join( '%d %s' % (index, name) for (index, name) in sorted((index, name) for (name, index) in self._pathogens.items()) ), file=fp)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_transform_chrom'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'try_statement', 'children': ['7', '15', '39']}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '15', 'type': 'except_clause', 'children': ['16']}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23', '26', '33']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '20', 'type': 'list', 'children': ['21', '22'], 'value': "['X', 'Y']"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'X'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'Y'"}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'chrom'}; {'id': '26', 'type': 'elif_clause', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'MT'"}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'_MT'"}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'__'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'chrom'}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'%02d'"}
def _transform_chrom(chrom): try: c = int(chrom) except: if chrom in ['X', 'Y']: return chrom elif chrom == 'MT': return '_MT' else: return '__' + chrom else: return '%02d' % c
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_show'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_runshell'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '18']}; {'id': '12', 'type': 'list', 'children': ['13', '14', '15'], 'value': "[brctlexe, 'show', self.name]"}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'brctlexe'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'show'"}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"Could not show %s."'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'subscript', 'children': ['25', '36']}, {'id': '25', 'type': 'call', 'children': ['26', '35']}; {'id': '26', 'type': 'attribute', 'children': ['27', '34']}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'slice', 'children': ['37', '38']}, {'id': '37', 'type': 'integer', 'children': [], 'value': '7'}
def _show(self): p = _runshell([brctlexe, 'show', self.name], "Could not show %s." % self.name) return p.stdout.read().split()[7:]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_assembly'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '5', 'type': 'block', 'children': ['6', '23']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pkg_resources'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'resource_filename'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_assy_path_fmt'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'load'}; {'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': 'gzip'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '38']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '37', 'type': 'string', 'children': [], 'value': '"rt"'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'encoding'}
def get_assembly(name): fn = pkg_resources.resource_filename( __name__, _assy_path_fmt.format(name=name)) return json.load(gzip.open(fn, mode="rt", encoding="utf-8"))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'coverageInfo'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '59']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'titleAlignment'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hsp'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'titleAlignment'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hsps'}; {'id': '22', 'type': 'block', 'children': ['23', '31']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'hsp'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'score'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '36', '47']}; {'id': '32', 'type': 'tuple_pattern', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'subjectOffset'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'titleAlignment'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'walkHSP'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'hsp'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'includeWhiskers'}; {'id': '46', 'type': 'False', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'subjectOffset'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'tuple', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '59', 'type': 'return_statement', 'children': ['60']}
def coverageInfo(self): result = defaultdict(list) for titleAlignment in self: for hsp in titleAlignment.hsps: score = hsp.score.score for (subjectOffset, base, _) in titleAlignment.read.walkHSP( hsp, includeWhiskers=False): result[subjectOffset].append((score, base)) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'minMatchingReads'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'minMedianScore'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'withScoreBetterThan'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'minNewReads'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'minCoverage'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortOn'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'maxScore'"}; {'id': '26', 'type': 'block', 'children': ['27', '60', '78', '123', '238']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31', '36']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'minNewReads'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'id': '37', 'type': 'block', 'children': ['38', '54']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '44']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ReadSetFilter'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'minNewReads'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'TitlesAlignments'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '69', '72', '75']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'readsAlignments'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'scoreClass'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'importReadsAlignmentsTitles'}, {'id': '77', 'type': 'False', 'children': []}; {'id': '78', 'type': 'if_statement', 'children': ['79', '89', '113']}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '83'], 'value': 'and'}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}; {'id': '82', 'type': 'None', 'children': []}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '>'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94', '102']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '<'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'raise_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'maxTitles (%r) cannot be negative.'"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'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': 'sortTitles'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sortOn'}, {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'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': 'titles'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '126', 'type': 'block', 'children': ['127', '140', '146', '161', '186', '201', '216', '230']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '138']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '132'], 'value': 'and'}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}, {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '137'], 'value': '=='}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'maxTitles'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'break_statement', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '159']}, {'id': '147', 'type': 'parenthesized_expression', 'children': ['148'], 'value': '()'}; {'id': '148', 'type': 'boolean_operator', 'children': ['149', '152'], 'value': 'and'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'minMatchingReads'}, {'id': '151', 'type': 'None', 'children': []}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': '<'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'readCount'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'minMatchingReads'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'continue_statement', 'children': []}, {'id': '161', 'type': 'if_statement', 'children': ['162', '184']}; {'id': '162', 'type': 'parenthesized_expression', 'children': ['163'], 'value': '()'}, {'id': '163', 'type': 'boolean_operator', 'children': ['164', '167'], 'value': 'and'}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'minMedianScore'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '178'], 'value': '<'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'scoreClass'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'medianScore'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'scoreClass'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'minMedianScore'}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'continue_statement', 'children': []}; {'id': '186', 'type': 'if_statement', 'children': ['187', '199']}, {'id': '187', 'type': 'parenthesized_expression', 'children': ['188'], 'value': '()'}; {'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'withScoreBetterThan'}, {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'not_operator', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'hasScoreBetterThan'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'withScoreBetterThan'}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'continue_statement', 'children': []}, {'id': '201', 'type': 'if_statement', 'children': ['202', '214']}; {'id': '202', 'type': 'parenthesized_expression', 'children': ['203'], 'value': '()'}, {'id': '203', 'type': 'boolean_operator', 'children': ['204', '207'], 'value': 'and'}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'is'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'minCoverage'}; {'id': '206', 'type': 'None', 'children': []}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '213'], 'value': '<'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '212', 'type': 'argument_list', 'children': []}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'minCoverage'}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'continue_statement', 'children': []}; {'id': '216', 'type': 'if_statement', 'children': ['217', '228']}, {'id': '217', 'type': 'parenthesized_expression', 'children': ['218'], 'value': '()'}; {'id': '218', 'type': 'boolean_operator', 'children': ['219', '220'], 'value': 'and'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}; {'id': '220', 'type': 'not_operator', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'readSetFilter'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'accept'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'continue_statement', 'children': []}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'addTitle'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'titleAlignments'}; {'id': '238', 'type': 'return_statement', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'result'}
def filter(self, minMatchingReads=None, minMedianScore=None, withScoreBetterThan=None, minNewReads=None, minCoverage=None, maxTitles=None, sortOn='maxScore'): if minNewReads is None: readSetFilter = None else: if self.readSetFilter is None: self.readSetFilter = ReadSetFilter(minNewReads) readSetFilter = self.readSetFilter result = TitlesAlignments( self.readsAlignments, self.scoreClass, self.readSetFilter, importReadsAlignmentsTitles=False) if maxTitles is not None and len(self) > maxTitles: if maxTitles < 0: raise ValueError('maxTitles (%r) cannot be negative.' % maxTitles) else: titles = self.sortTitles(sortOn) else: titles = self.keys() for title in titles: if maxTitles is not None and len(result) == maxTitles: break titleAlignments = self[title] if (minMatchingReads is not None and titleAlignments.readCount() < minMatchingReads): continue if (minMedianScore is not None and self.scoreClass(titleAlignments.medianScore()) < self.scoreClass(minMedianScore)): continue if (withScoreBetterThan is not None and not titleAlignments.hasScoreBetterThan(withScoreBetterThan)): continue if (minCoverage is not None and titleAlignments.coverage() < minCoverage): continue if (readSetFilter and not readSetFilter.accept(title, titleAlignments)): continue result.addTitle(title, titleAlignments) return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortTitles'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '40', '65', '95', '120', '127']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'length'"}, {'id': '21', 'type': 'block', 'children': ['22']}; {'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', '27', '30']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '29', 'type': 'True', 'children': []}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'lambda', 'children': ['33', '35']}, {'id': '33', 'type': 'lambda_parameters', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'subjectLength'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'maxScore'"}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '53']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '52', 'type': 'True', 'children': []}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '55', 'type': 'lambda', 'children': ['56', '58']}; {'id': '56', 'type': 'lambda_parameters', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'bestHsp'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'medianScore'"}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '77', 'type': 'True', 'children': []}; {'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '80', 'type': 'lambda', 'children': ['81', '83']}, {'id': '81', 'type': 'lambda_parameters', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'scoreClass'}, {'id': '87', 'type': 'argument_list', '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': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'medianScore'}; {'id': '94', 'type': 'argument_list', 'children': []}, {'id': '95', 'type': 'if_statement', 'children': ['96', '99']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'readCount'"}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105', '108']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '107', 'type': 'True', 'children': []}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '110', 'type': 'lambda', 'children': ['111', '113']}, {'id': '111', 'type': 'lambda_parameters', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'readCount'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '=='}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'by'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'titles'}, {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'concatenated_string', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': '\'Sort attribute must be one of "length", "maxScore", \''}, {'id': '133', 'type': 'string', 'children': [], 'value': '\'"medianScore", "readCount", "title".\''}
def sortTitles(self, by): titles = sorted(iter(self)) if by == 'length': return sorted( titles, reverse=True, key=lambda title: self[title].subjectLength) if by == 'maxScore': return sorted( titles, reverse=True, key=lambda title: self[title].bestHsp()) if by == 'medianScore': return sorted( titles, reverse=True, key=lambda title: self.scoreClass(self[title].medianScore())) if by == 'readCount': return sorted( titles, reverse=True, key=lambda title: self[title].readCount()) if by == 'title': return titles raise ValueError('Sort attribute must be one of "length", "maxScore", ' '"medianScore", "readCount", "title".')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'summary'}, {'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': 'sortOn'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '12', 'type': 'conditional_expression', 'children': ['13', '14', '17'], 'value': 'if'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sortOn'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sortTitles'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sortOn'}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'yield', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'summary'}, {'id': '35', 'type': 'argument_list', 'children': []}
def summary(self, sortOn=None): titles = self if sortOn is None else self.sortTitles(sortOn) for title in titles: yield self[title].summary()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tabSeparatedSummary'}, {'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': 'sortOn'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '43']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '21']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'titleSummary'}, {'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': 'summary'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sortOn'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '42'], 'value': '%'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'list', 'children': ['35', '36', '37', '38', '39', '40', '41'], 'value': "[\n '%(coverage)f',\n '%(medianScore)f',\n '%(bestScore)f',\n '%(readCount)d',\n '%(hspCount)d',\n '%(subjectLength)d',\n '%(subjectTitle)s',\n ]"}, {'id': '35', 'type': 'string', 'children': [], 'value': "'%(coverage)f'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'%(medianScore)f'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'%(bestScore)f'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'%(readCount)d'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'%(hspCount)d'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'%(subjectLength)d'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'%(subjectTitle)s'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'titleSummary'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'}
def tabSeparatedSummary(self, sortOn=None): result = [] for titleSummary in self.summary(sortOn): result.append('\t'.join([ '%(coverage)f', '%(medianScore)f', '%(bestScore)f', '%(readCount)d', '%(hspCount)d', '%(subjectLength)d', '%(subjectTitle)s', ]) % titleSummary) return '\n'.join(result)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'infer_namespaces'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ac'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'list_comprehension', 'children': ['8', '9', '18']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '9', 'type': 'for_in_clause', 'children': ['10', '13']}; {'id': '10', 'type': 'pattern_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'ac_namespace_regexps'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'if_clause', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}
def infer_namespaces(ac): return [v for k, v in ac_namespace_regexps.items() if k.match(ac)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_digraph'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '18', '171']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'digraph'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_nx'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'DiGraph'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '23']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'equation'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'equations'}, {'id': '23', 'type': 'block', 'children': ['24', '45', '73', '82', '110', '119', '146', '156']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '30']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28', '29']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reactants'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'arrow'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_split_arrows'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'equation'}, {'id': '45', 'type': 'try_statement', 'children': ['46', '64']}; {'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': 'attr'}; {'id': '50', 'type': 'call', 'children': ['51', '63']}, {'id': '51', 'type': 'attribute', 'children': ['52', '62']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'equation'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'to_series'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '60']}, {'id': '57', 'type': 'string', 'children': [], 'value': '"reactants"'}; {'id': '58', 'type': 'list_splat', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '60', 'type': 'dictionary_splat', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'to_dict'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'except_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '72', 'type': 'argument_list', 'children': []}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'digraph'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reactants'}; {'id': '80', 'type': 'dictionary_splat', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '82', 'type': 'try_statement', 'children': ['83', '101']}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '87', 'type': 'call', 'children': ['88', '100']}; {'id': '88', 'type': 'attribute', 'children': ['89', '99']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'equation'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'to_series'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '97']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"products"'}, {'id': '95', 'type': 'list_splat', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '97', 'type': 'dictionary_splat', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'except_clause', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'digraph'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'add_node'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'products'}, {'id': '117', 'type': 'dictionary_splat', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '119', 'type': 'try_statement', 'children': ['120', '137']}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '124', 'type': 'call', 'children': ['125', '136']}, {'id': '125', 'type': 'attribute', 'children': ['126', '135']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'equation'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'to_series'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '133']}, {'id': '131', 'type': 'list_splat', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '133', 'type': 'dictionary_splat', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'except_clause', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'digraph'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'add_edge'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153', '154']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'reactants'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '154', 'type': 'dictionary_splat', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '=='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'arrow'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'<=>'"}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'digraph'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'reactants'}, {'id': '169', 'type': 'dictionary_splat', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '171', 'type': 'return_statement', 'children': ['172']}
def to_digraph(self, *args, **kwargs): digraph = _nx.DiGraph() for equation in self.equations: reactants, arrow, products = [value.strip() for value in _split_arrows(str(equation))] try: attr = equation.to_series("reactants", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(reactants, **attr) try: attr = equation.to_series("products", *args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_node(products, **attr) try: attr = equation.to_series(*args, **kwargs).to_dict() except ValueError: attr = dict() digraph.add_edge(reactants, products, **attr) if arrow == '<=>': digraph.add_edge(products, reactants, **attr) return digraph
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_streams'}, {'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': 'game'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'channels'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '25'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'block', 'children': ['18', '33', '37', '41', '79', '95', '108']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'game'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Game'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'game'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'game'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'channelnames'}; {'id': '36', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'cparam'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'channels'}, {'id': '43', 'type': 'block', 'children': ['44', '70']}; {'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'channels'}, {'id': '47', 'type': 'block', 'children': ['48', '63']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '56']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'Channel'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'channelnames'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cparam'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'string', 'children': [], 'value': "','"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'channelnames'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '82', 'type': 'dictionary', 'children': ['83', '86', '89', '92']}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'limit'"}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '89', 'type': 'pair', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'game'"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'game'}; {'id': '92', 'type': 'pair', 'children': ['93', '94']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'channel'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cparam'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'kraken_request'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'GET'"}; {'id': '104', 'type': 'string', 'children': [], 'value': "'streams'"}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'models'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'Stream'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'wrap_search'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}
def get_streams(self, game=None, channels=None, limit=25, offset=0): if isinstance(game, models.Game): game = game.name channelnames = [] cparam = None if channels: for c in channels: if isinstance(c, models.Channel): c = c.name channelnames.append(c) cparam = ','.join(channelnames) params = {'limit': limit, 'offset': offset, 'game': game, 'channel': cparam} r = self.kraken_request('GET', 'streams', params=params) return models.Stream.wrap_search(r)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_queryset'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '139']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'sort_by'"}, {'id': '21', 'type': 'if_statement', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '40', '50']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'el'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'el'}, {'id': '33', 'type': 'attribute', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '50', 'type': 'else_clause', 'children': ['51']}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'if_statement', 'children': ['53', '58', '81']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'in'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '58', 'type': 'block', 'children': ['59', '67']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '67', 'type': 'try_statement', 'children': ['68', '78']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '78', 'type': 'except_clause', 'children': ['79']}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'raise_statement', 'children': []}, {'id': '81', 'type': 'elif_clause', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86', '130']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '92', '108']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '91'], 'value': '!='}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '96', 'type': 'subscript', 'children': ['97', '102']}, {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'cl'"}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'list_display'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '107'], 'value': '-'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'else_clause', 'children': ['109']}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '115', 'type': 'subscript', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'cl'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'list_display'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '129'], 'value': '-'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'queryset'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '139', 'type': 'return_statement', 'children': ['140']}
def sort_queryset(queryset, request, context=None): sort_by = request.GET.get('sort_by') if sort_by: if sort_by in [el.name for el in queryset.model._meta.fields]: queryset = queryset.order_by(sort_by) else: if sort_by in request.session: sort_by = request.session[sort_by] try: queryset = queryset.order_by(sort_by) except: raise elif context is not None: if sort_by[0] != '-': sort_by = context['cl'].list_display[int(sort_by) - 1] else: sort_by = '-' + context['cl'].list_display[abs(int(sort_by)) - 1] queryset = queryset.order_by(sort_by) return queryset
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'percentile'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '25', '45']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '24'], 'value': '-'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '23'], 'value': '*'}, {'id': '19', 'type': 'parenthesized_expression', 'children': ['20'], 'value': '()'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '/'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '22', 'type': 'float', 'children': [], 'value': '100.0'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '24', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '33']}; {'id': '26', 'type': 'boolean_operator', 'children': ['27', '30'], 'value': 'or'}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '>'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'raise_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'StatisticsError'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"Too few data points ({}) for {}th percentile"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'idx'}
def percentile(data, n): size = len(data) idx = (n / 100.0) * size - 0.5 if idx < 0 or idx > size: raise StatisticsError("Too few data points ({}) for {}th percentile".format(size, n)) return data[int(idx)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_histogram'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '28', '34', '41', '48', '58', '68', '88']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '<'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'StatisticsError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Too few data points ({}) for get_histogram'"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'min_'}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}, {'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': 'max_'}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '39', 'type': 'unary_operator', 'children': ['40'], 'value': '-'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stdev'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'bins'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_histogram_bins'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '56', '57']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'min_'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'max_'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'std'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '61', 'type': 'dictionary_comprehension', 'children': ['62', '65']}; {'id': '62', 'type': 'pair', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'bin_'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bins'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '<='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'bin_'}; {'id': '80', 'type': 'block', 'children': ['81', '87']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'augmented_assignment', 'children': ['83', '86'], 'value': '+='}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bin_'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'break_statement', 'children': []}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'res'}
def get_histogram(data): count = len(data) if count < 2: raise StatisticsError('Too few data points ({}) for get_histogram'.format(count)) min_ = data[0] max_ = data[-1] std = stdev(data) bins = get_histogram_bins(min_, max_, std, count) res = {x: 0 for x in bins} for value in data: for bin_ in bins: if value <= bin_: res[bin_] += 1 break return sorted(iteritems(res))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_geohash_tables'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'listofprecisions'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15', '19', '47', '56', '64', '68', '88', '98', '124', '283']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n\tsort_by - field to sort by for each group\n\treturn_squares - boolean arg if true returns a list of squares instead of writing out to table\n\t'''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'return_squares'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'COUNT'"}, {'id': '19', 'type': 'for_statement', 'children': ['20', '23', '28']}; {'id': '20', 'type': 'pattern_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '38']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '=='}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'sort_by'"}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_by'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'return_squares'"}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'return_squares'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '50', 'type': 'subscript', 'children': ['51', '55']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'df2list'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '61', 'type': 'slice', 'children': ['62', '63']}; {'id': '62', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '63', 'type': 'colon', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'originaltable'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '73']}, {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'COUNT'"}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'originaltable'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'originaltable'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '84']}; {'id': '82', 'type': 'list', 'children': ['83'], 'value': '[sort_by]'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '86', 'type': 'list', 'children': ['87'], 'value': '[0]'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'listofprecisions'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'listofprecisions'}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '97', 'type': 'True', 'children': []}; {'id': '98', 'type': 'if_statement', 'children': ['99', '109', '115']}, {'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'and'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'return_squares'}; {'id': '102', 'type': 'True', 'children': []}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '108'], 'value': '=='}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'listofprecisions'}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'total_list'}, {'id': '113', 'type': 'list', 'children': ['114'], 'value': '[table]'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '115', 'type': 'elif_clause', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'return_squares'}; {'id': '118', 'type': 'True', 'children': []}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'total_list'}, {'id': '123', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'listofprecisions'}, {'id': '127', 'type': 'block', 'children': ['128', '135', '139', '153', '176', '190', '198', '203', '245', '252']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'originaltable'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'GEOHASH'"}; {'id': '144', 'type': 'subscript', 'children': ['145', '150']}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'GEOHASH'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '150', 'type': 'slice', 'children': ['151', '152']}, {'id': '151', 'type': 'colon', 'children': []}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '156', 'type': 'call', 'children': ['157', '175']}, {'id': '157', 'type': 'attribute', 'children': ['158', '174']}; {'id': '158', 'type': 'call', 'children': ['159', '168']}, {'id': '159', 'type': 'attribute', 'children': ['160', '167']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '166'], 'value': '+'}, {'id': '163', 'type': 'list', 'children': ['164', '165'], 'value': "['GEOHASH','COUNT']"}; {'id': '164', 'type': 'string', 'children': [], 'value': "'GEOHASH'"}, {'id': '165', 'type': 'string', 'children': [], 'value': "'COUNT'"}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '171']}, {'id': '169', 'type': 'list', 'children': ['170'], 'value': "['GEOHASH']"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'GEOHASH'"}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '173', 'type': 'True', 'children': []}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '186']}; {'id': '184', 'type': 'list', 'children': ['185'], 'value': '[sort_by]'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '188', 'type': 'list', 'children': ['189'], 'value': '[0]'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'reset_index'}, {'id': '197', 'type': 'argument_list', 'children': []}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'newsquares'}, {'id': '201', 'type': 'list', 'children': ['202'], 'value': '[header]'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '203', 'type': 'for_statement', 'children': ['204', '205', '213']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '205', 'type': 'subscript', 'children': ['206', '210']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'df2list'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '210', 'type': 'slice', 'children': ['211', '212']}, {'id': '211', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '212', 'type': 'colon', 'children': []}, {'id': '213', 'type': 'block', 'children': ['214', '223', '238']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'points'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'get_points_geohash'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'newrow'}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '233'], 'value': '+'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '232'], 'value': '+'}; {'id': '228', 'type': 'list', 'children': ['229'], 'value': '[row[0]]'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'points'}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '235', 'type': 'slice', 'children': ['236', '237']}; {'id': '236', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '237', 'type': 'colon', 'children': []}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'newsquares'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'newrow'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'list2df'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'newsquares'}; {'id': '252', 'type': 'if_statement', 'children': ['253', '256', '264']}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': '=='}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'return_squares'}, {'id': '255', 'type': 'True', 'children': []}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'total_list'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '264', 'type': 'else_clause', 'children': ['265']}, {'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': 'table'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'to_csv'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '280']}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '279'], 'value': '+'}, {'id': '273', 'type': 'binary_operator', 'children': ['274', '275'], 'value': '+'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'squares'"}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '279', 'type': 'string', 'children': [], 'value': "'.csv'"}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '282', 'type': 'False', 'children': []}, {'id': '283', 'type': 'if_statement', 'children': ['284', '287', '290']}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': '=='}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'return_squares'}; {'id': '286', 'type': 'True', 'children': []}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'return_statement', 'children': ['289']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'total_list'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'print_statement', 'children': ['293']}, {'id': '293', 'type': 'string', 'children': [], 'value': "'Wrote output squares tables to csv files.'"}
def make_geohash_tables(table,listofprecisions,**kwargs): ''' sort_by - field to sort by for each group return_squares - boolean arg if true returns a list of squares instead of writing out to table ''' return_squares = False sort_by = 'COUNT' for key,value in kwargs.iteritems(): if key == 'sort_by': sort_by = value if key == 'return_squares': return_squares = value header = df2list(table)[0] columns = header[10:] originaltable = table if not sort_by == 'COUNT': originaltable = originaltable.sort([sort_by],ascending=[0]) listofprecisions = sorted(listofprecisions,reverse=True) if return_squares == True and listofprecisions[-1] == 8: total_list = [table] elif return_squares == True: total_list = [] for row in listofprecisions: precision = int(row) table = originaltable table['GEOHASH'] = table.GEOHASH.str[:precision] table = table[['GEOHASH','COUNT']+columns].groupby(['GEOHASH'],sort=True).sum() table = table.sort([sort_by],ascending=[0]) table = table.reset_index() newsquares = [header] for row in df2list(table)[1:]: points = get_points_geohash(row[0]) newrow = [row[0]] + points + row[1:] newsquares.append(newrow) table = list2df(newsquares) if return_squares == True: total_list.append(table) else: table.to_csv('squares' + str(precision) + '.csv',index=False) if return_squares == True: return total_list else: print 'Wrote output squares tables to csv files.'
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'coercer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataSets'}; {'id': '6', 'type': 'block', 'children': ['7', '36', '50', '64', '73', '230', '237']}, {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'makeSetter'}, {'id': '9', 'type': 'parameters', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '12', 'type': 'block', 'children': ['13', '34']}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '17']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': 'setter'}, {'id': '15', 'type': 'parameters', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'defaultObject'}, {'id': '17', 'type': 'block', 'children': ['18', '26']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '25']}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_idsToObjects'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'defaultObject'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '33']}; {'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': '_lastValues'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'setter'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_coerceAll'}, {'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': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_extractCreations'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'dataSets'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'edited'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_coerceAll'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_extractEdits'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'dataSets'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'coerceDeferred'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'gatherResults'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list', 'children': ['71', '72'], 'value': '[created, edited]'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'created'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'edited'}, {'id': '73', 'type': 'function_definition', 'children': ['74', '75', '79']}; {'id': '74', 'type': 'function_name', 'children': [], 'value': 'cbCoerced'}, {'id': '75', 'type': 'parameters', 'children': ['76']}; {'id': '76', 'type': 'tuple_pattern', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'created'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'edited'}, {'id': '79', 'type': 'block', 'children': ['80', '86', '90', '118', '122', '176', '180', '223']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'receivedIdentifiers'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'createObjects'}, {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '90', 'type': 'for_statement', 'children': ['91', '94', '95']}, {'id': '91', 'type': 'tuple_pattern', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'created'}, {'id': '95', 'type': 'block', 'children': ['96', '103']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'receivedIdentifiers'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'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': 'createObjects'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'CreateObject'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'dataSet'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'makeSetter'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'editObjects'}, {'id': '121', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '122', 'type': 'for_statement', 'children': ['123', '126', '127']}, {'id': '123', 'type': 'tuple_pattern', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'edited'}, {'id': '127', 'type': 'block', 'children': ['128', '135', '143']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'receivedIdentifiers'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'lastValues'}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_lastValues'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '!='}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'lastValues'}, {'id': '147', 'type': 'block', 'children': ['148', '157', '168']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'modelObject'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '_objectFromID'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'editObjects'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'EditObject'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'modelObject'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '175']}; {'id': '170', 'type': 'subscript', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': '_lastValues'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'dataSet'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'deleted'}, {'id': '179', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '180', 'type': 'for_statement', 'children': ['181', '182', '190']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '189'], 'value': '-'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_idsToObjects'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'receivedIdentifiers'}; {'id': '190', 'type': 'block', 'children': ['191', '200', '214']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '_objectFromID'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '206']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'is'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'existing'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': '_NO_OBJECT_MARKER'}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'deleted'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'existing'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '221']}; {'id': '216', 'type': 'attribute', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_idsToObjects'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'identifier'}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ListChanges'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228', '229']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'createObjects'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'editObjects'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'deleted'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'coerceDeferred'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'addCallback'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'cbCoerced'}, {'id': '237', 'type': 'return_statement', 'children': ['238']}
def coercer(self, dataSets): def makeSetter(identifier, values): def setter(defaultObject): self._idsToObjects[identifier] = defaultObject self._lastValues[identifier] = values return setter created = self._coerceAll(self._extractCreations(dataSets)) edited = self._coerceAll(self._extractEdits(dataSets)) coerceDeferred = gatherResults([created, edited]) def cbCoerced((created, edited)): receivedIdentifiers = set() createObjects = [] for (identifier, dataSet) in created: receivedIdentifiers.add(identifier) createObjects.append( CreateObject(dataSet, makeSetter(identifier, dataSet))) editObjects = [] for (identifier, dataSet) in edited: receivedIdentifiers.add(identifier) lastValues = self._lastValues[identifier] if dataSet != lastValues: modelObject = self._objectFromID(identifier) editObjects.append(EditObject(modelObject, dataSet)) self._lastValues[identifier] = dataSet deleted = [] for identifier in set(self._idsToObjects) - receivedIdentifiers: existing = self._objectFromID(identifier) if existing is not self._NO_OBJECT_MARKER: deleted.append(existing) self._idsToObjects.pop(identifier) return ListChanges(createObjects, editObjects, deleted) coerceDeferred.addCallback(cbCoerced) return coerceDeferred
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zcard'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'with_statement', 'children': ['8', '16']}; {'id': '8', 'type': 'with_clause', 'children': ['9']}, {'id': '9', 'type': 'with_item', 'children': ['10']}; {'id': '10', 'type': 'as_pattern', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '14', 'type': 'as_pattern_target', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'zcard'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'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': 'redis_key'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}
def zcard(self, name): with self.pipe as pipe: return pipe.zcard(self.redis_key(name))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zscore'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'with_statement', 'children': ['9', '17']}, {'id': '9', 'type': 'with_clause', 'children': ['10']}; {'id': '10', 'type': 'with_item', 'children': ['11']}, {'id': '11', 'type': 'as_pattern', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '15', 'type': 'as_pattern_target', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'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': 'pipe'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'zscore'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '30']}; {'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': 'redis_key'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'valueparse'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'}
def zscore(self, name, value): with self.pipe as pipe: return pipe.zscore(self.redis_key(name), self.valueparse.encode(value))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrank'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'with_statement', 'children': ['9', '17']}, {'id': '9', 'type': 'with_clause', 'children': ['10']}; {'id': '10', 'type': 'with_item', 'children': ['11']}, {'id': '11', 'type': 'as_pattern', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '15', 'type': 'as_pattern_target', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '17', 'type': 'block', 'children': ['18', '29']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'valueparse'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'zrank'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '41']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'}
def zrank(self, name, value): with self.pipe as pipe: value = self.valueparse.encode(value) return pipe.zrank(self.redis_key(name), value)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zlexcount'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'with_statement', 'children': ['10', '18']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}, {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'as_pattern', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '16', 'type': 'as_pattern_target', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'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': 'pipe'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'zlexcount'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '31', '32']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'min'}
def zlexcount(self, name, min, max): with self.pipe as pipe: return pipe.zlexcount(self.redis_key(name), min, max)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zrevrangebylex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'with_statement', 'children': ['16', '24']}; {'id': '16', 'type': 'with_clause', 'children': ['17']}, {'id': '17', 'type': 'with_item', 'children': ['18']}; {'id': '18', 'type': 'as_pattern', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '22', 'type': 'as_pattern_target', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '24', 'type': 'block', 'children': ['25', '31', '53', '75', '82']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Future'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'zrevrangebylex'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '45', '46', '47', '50']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '53', 'type': 'function_definition', 'children': ['54', '55', '56']}; {'id': '54', 'type': 'function_name', 'children': [], 'value': 'cb'}, {'id': '55', 'type': 'parameters', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'list_comprehension', 'children': ['64', '72']}; {'id': '64', 'type': 'call', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'valueparse'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pipe'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'on_execute'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '82', 'type': 'return_statement', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'f'}
def zrevrangebylex(self, name, max, min, start=None, num=None): with self.pipe as pipe: f = Future() res = pipe.zrevrangebylex(self.redis_key(name), max, min, start=start, num=num) def cb(): f.set([self.valueparse.decode(v) for v in res]) pipe.on_execute(cb) return f
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'zremrangebylex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'with_statement', 'children': ['10', '18']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}, {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'as_pattern', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'id': '16', 'type': 'as_pattern_target', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pipe'}; {'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': 'pipe'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'zremrangebylex'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '31', '32']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'redis_key'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'min'}
def zremrangebylex(self, name, min, max): with self.pipe as pipe: return pipe.zremrangebylex(self.redis_key(name), min, max)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attributeID'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '29', '46', '83', '89']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isAscending'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'defaultSortAscending'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'attributeID'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '37']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '36'], 'value': 'is'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'None', 'children': []}, {'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': 'Unsortable'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'column %r has no sort attribute'"}; {'id': '44', 'type': 'tuple', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'attributeID'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '71']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'if_statement', 'children': ['54', '59', '64']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'isAscending'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73', '77']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'isAscending'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_updateResults'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '101']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_sortAttributeValue'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '101', 'type': 'True', 'children': []}
def resort(self, attributeID, isAscending=None): if isAscending is None: isAscending = self.defaultSortAscending newSortColumn = self.columns[attributeID] if newSortColumn.sortAttribute() is None: raise Unsortable('column %r has no sort attribute' % (attributeID,)) if self.currentSortColumn == newSortColumn: if self.isAscending == isAscending: offset = 0 else: offset = -1 else: offset = 0 self.currentSortColumn = newSortColumn self.isAscending = isAscending self._updateResults(self._sortAttributeValue(offset), True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sortAttributeValue'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '6', 'type': 'block', 'children': ['7', '42']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11', '36']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_currentResults'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pageStart'}, {'id': '15', 'type': 'tuple', 'children': ['16', '27']}; {'id': '16', 'type': 'subscript', 'children': ['17', '22']}, {'id': '17', 'type': 'subscript', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_currentResults'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'attributeID'}, {'id': '27', 'type': 'attribute', 'children': ['28', '35']}; {'id': '28', 'type': 'subscript', 'children': ['29', '34']}, {'id': '29', 'type': 'subscript', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_currentResults'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'__item__'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'storeID'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'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': 'pageStart'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pageStart'}
def _sortAttributeValue(self, offset): if self._currentResults: pageStart = (self._currentResults[offset][ self.currentSortColumn.attributeID], self._currentResults[offset][ '__item__'].storeID) else: pageStart = None return pageStart
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'columnName'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '21', '34', '62']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'csc'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'columnName'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'raise_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Unsortable'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'column %r has no sort attribute'"}; {'id': '32', 'type': 'tuple', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'columnName'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38', '48']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'csc'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'isAscending'}; {'id': '48', 'type': 'else_clause', 'children': ['49']}, {'id': '49', 'type': 'block', 'children': ['50', '56']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'newSortColumn'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isAscending'}, {'id': '61', 'type': 'True', 'children': []}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isAscending'}
def resort(self, columnName): csc = self.currentSortColumn newSortColumn = self.columns[columnName] if newSortColumn is None: raise Unsortable('column %r has no sort attribute' % (columnName,)) if csc is newSortColumn: self.isAscending = not self.isAscending else: self.currentSortColumn = newSortColumn self.isAscending = True return self.isAscending
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rowsAfterValue'}, {'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': 'count'}, {'id': '7', 'type': 'block', 'children': ['8', '58']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '24']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'query'}; {'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': 'inequalityQuery'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'else_clause', 'children': ['25']}, {'id': '25', 'type': 'block', 'children': ['26', '35', '45']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pyvalue'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_toComparableValue'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}; {'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': 'query'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'inequalityQuery'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56', '57']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '>='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pyvalue'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '57', 'type': 'True', 'children': []}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'constructRows'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}
def rowsAfterValue(self, value, count): if value is None: query = self.inequalityQuery(None, count, True) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery(currentSortAttribute >= pyvalue, count, True) return self.constructRows(query)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rowsBeforeValue'}, {'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': 'count'}, {'id': '7', 'type': 'block', 'children': ['8', '58']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '24']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'is'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'query'}; {'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': 'inequalityQuery'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'else_clause', 'children': ['25']}, {'id': '25', 'type': 'block', 'children': ['26', '35', '45']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pyvalue'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_toComparableValue'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}; {'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': 'query'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'inequalityQuery'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56', '57']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pyvalue'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '57', 'type': 'False', 'children': []}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'subscript', 'children': ['60', '66']}; {'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': 'constructRows'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '66', 'type': 'slice', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'colon', 'children': []}; {'id': '68', 'type': 'colon', 'children': []}, {'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'}
def rowsBeforeValue(self, value, count): if value is None: query = self.inequalityQuery(None, count, False) else: pyvalue = self._toComparableValue(value) currentSortAttribute = self.currentSortColumn.sortAttribute() query = self.inequalityQuery( currentSortAttribute < pyvalue, count, False) return self.constructRows(query)[::-1]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rowsBeforeItem'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '31', '56', '65', '72', '100']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}, {'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': 'currentSortColumn'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}, {'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': 'value'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '__get__'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'firstQuery'}; {'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': 'inequalityQuery'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '54', '55']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'AND'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '51'], 'value': '<'}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'itemType'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'storeID'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'storeID'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'constructRows'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'firstQuery'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '-='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '74', 'type': 'block', 'children': ['75', '88']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'secondQuery'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'inequalityQuery'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '86', '87']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '<'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'currentSortAttribute'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '87', 'type': 'False', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'constructRows'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'secondQuery'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '103', 'type': 'slice', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'colon', 'children': []}, {'id': '105', 'type': 'colon', 'children': []}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}
def rowsBeforeItem(self, item, count): currentSortAttribute = self.currentSortColumn.sortAttribute() value = currentSortAttribute.__get__(item, type(item)) firstQuery = self.inequalityQuery( AND(currentSortAttribute == value, self.itemType.storeID < item.storeID), count, False) results = self.constructRows(firstQuery) count -= len(results) if count: secondQuery = self.inequalityQuery(currentSortAttribute < value, count, False) results.extend(self.constructRows(secondQuery)) return results[::-1]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getTableMetadata'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '61', '88']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'coltypes'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']}, {'id': '11', 'type': 'tuple_pattern', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'colname'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '32', '40', '53']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortable'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '31'], 'value': 'is'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'coltype'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'getType'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'coltype'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'coltype'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'coltype'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'coltypes'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'colname'}; {'id': '58', 'type': 'tuple', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'coltype'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sortable'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65', '82']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'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': 'csc'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'unicode'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '81']}; {'id': '72', 'type': 'attribute', 'children': ['73', '80']}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sortAttribute'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '82', 'type': 'else_clause', 'children': ['83']}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'csc'}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'list', 'children': ['90', '93', '94', '99', '100'], 'value': '[self.columnNames, coltypes, self.requestCurrentSize(),\n csc, self.isAscending]'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'columnNames'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'coltypes'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'requestCurrentSize'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'csc'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}
def getTableMetadata(self): coltypes = {} for (colname, column) in self.columns.iteritems(): sortable = column.sortAttribute() is not None coltype = column.getType() if coltype is not None: coltype = unicode(coltype, 'ascii') coltypes[colname] = (coltype, sortable) if self.currentSortColumn: csc = unicode(self.currentSortColumn.sortAttribute().attrname, 'ascii') else: csc = None return [self.columnNames, coltypes, self.requestCurrentSize(), csc, self.isAscending]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getInitialArguments'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'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': 'ic'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'IColumn'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'currentSortColumn'}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'list', 'children': ['17', '25', '30'], 'value': "[ic.attributeID.decode('ascii'),\n self._getColumnList(),\n self.isAscending]"}, {'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': 'ic'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'attributeID'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_getColumnList'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}
def getInitialArguments(self): ic = IColumn(self.currentSortColumn) return [ic.attributeID.decode('ascii'), self._getColumnList(), self.isAscending]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_database_sortmerna'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_path'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_pos'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'temp_dir'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'gettempdir'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '34', '43', '57', '66', '74', '86', '101', '112', '128', '134', '162']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'fasta_path'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"Error: path to fasta reference "'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"sequences must exist."'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'fasta_dir'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fasta_path'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '46']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '46', 'type': 'block', 'children': ['47', '53']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '52'], 'value': 'or'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'fasta_dir'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fasta_path'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index_basename'}; {'id': '60', 'type': 'subscript', 'children': ['61', '65']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'splitext'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'db_name'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'index_basename'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sdb'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'IndexDB'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83']}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '95']}; {'id': '88', 'type': 'attribute', 'children': ['89', '94']}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sdb'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'--ref'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"%s,%s"'}; {'id': '98', 'type': 'tuple', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fasta_path'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'db_name'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '110']}, {'id': '103', 'type': 'attribute', 'children': ['104', '109']}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sdb'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'--tmpdir'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'temp_dir'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '116']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'max_pos'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '126']}, {'id': '119', 'type': 'attribute', 'children': ['120', '125']}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sdb'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'--max_pos'"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'max_pos'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sdb'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'db_filepaths'}, {'id': '137', 'type': 'list_comprehension', 'children': ['138', '141', '150']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '141', 'type': 'for_in_clause', 'children': ['142', '145']}; {'id': '142', 'type': 'pattern_list', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'if_clause', 'children': ['151']}, {'id': '151', 'type': 'boolean_operator', 'children': ['152', '157'], 'value': 'and'}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'not'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '154', 'type': 'set', 'children': ['155', '156']}, {'id': '155', 'type': 'string', 'children': [], 'value': "'StdErr'"}; {'id': '156', 'type': 'string', 'children': [], 'value': "'StdOut'"}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '161', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '162', 'type': 'return_statement', 'children': ['163']}, {'id': '163', 'type': 'expression_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'db_name'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'db_filepaths'}
def build_database_sortmerna(fasta_path, max_pos=None, output_dir=None, temp_dir=tempfile.gettempdir(), HALT_EXEC=False): if fasta_path is None: raise ValueError("Error: path to fasta reference " "sequences must exist.") fasta_dir, fasta_filename = split(fasta_path) if not output_dir: output_dir = fasta_dir or '.' fasta_path = fasta_filename index_basename = splitext(fasta_filename)[0] db_name = join(output_dir, index_basename) sdb = IndexDB(WorkingDir=output_dir, HALT_EXEC=HALT_EXEC) sdb.Parameters['--ref'].on("%s,%s" % (fasta_path, db_name)) sdb.Parameters['--tmpdir'].on(temp_dir) if max_pos is not None: sdb.Parameters['--max_pos'].on(max_pos) app_result = sdb() db_filepaths = [v.name for k, v in app_result.items() if k not in {'StdErr', 'StdOut'} and hasattr(v, 'name')] return db_name, db_filepaths
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortmerna_ref_cluster'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'seq_path'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sortmerna_db'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'result_path'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tabular'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'max_e_value'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'similarity'}; {'id': '24', 'type': 'float', 'children': [], 'value': '0.97'}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'coverage'}, {'id': '27', 'type': 'float', 'children': [], 'value': '0.97'}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'best'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '36', 'type': 'False', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '47', '70', '102', '112', '119', '143', '159', '175', '191', '207', '221', '237', '243', '249', '266', '282', '288', '309', '328']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Sortmerna'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51', '63']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'seq_path'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '61']}; {'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': 'smr'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'--reads'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'seq_path'}, {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"Error: a read file is mandatory input."'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74', '90']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sortmerna_db'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '84']}, {'id': '77', 'type': 'attribute', 'children': ['78', '83']}; {'id': '78', 'type': 'subscript', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'--ref'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': '"%s,%s"'}, {'id': '87', 'type': 'tuple', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sortmerna_db'}; {'id': '90', 'type': 'else_clause', 'children': ['91']}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'raise_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '101'], 'value': '%'}, {'id': '97', 'type': 'concatenated_string', 'children': ['98', '99', '100']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"Error: an indexed database for reference set %s must"'}, {'id': '99', 'type': 'string', 'children': [], 'value': '" already exist.\\nUse indexdb_rna to index the"'}; {'id': '100', 'type': 'string', 'children': [], 'value': '" database."'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'result_path'}, {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'raise_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'string', 'children': [], 'value': '"Error: the result path must be set."'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'result_path'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '122', 'type': 'None', 'children': []}, {'id': '123', 'type': 'block', 'children': ['124', '132']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'output_file'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '131', 'type': 'string', 'children': [], 'value': '"sortmerna_otus"'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '141']}; {'id': '134', 'type': 'attribute', 'children': ['135', '140']}, {'id': '135', 'type': 'subscript', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'--aligned'"}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'output_file'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'max_e_value'}; {'id': '146', 'type': 'None', 'children': []}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '157']}; {'id': '150', 'type': 'attribute', 'children': ['151', '156']}, {'id': '151', 'type': 'subscript', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'-e'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'max_e_value'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'is'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'similarity'}; {'id': '162', 'type': 'None', 'children': []}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '173']}; {'id': '166', 'type': 'attribute', 'children': ['167', '172']}, {'id': '167', 'type': 'subscript', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '171', 'type': 'string', 'children': [], 'value': "'--id'"}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'similarity'}, {'id': '175', 'type': 'if_statement', 'children': ['176', '179']}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'is'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '189']}; {'id': '182', 'type': 'attribute', 'children': ['183', '188']}, {'id': '183', 'type': 'subscript', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'--coverage'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'coverage'}, {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '205']}; {'id': '198', 'type': 'attribute', 'children': ['199', '204']}, {'id': '199', 'type': 'subscript', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'--best'"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'best'}, {'id': '207', 'type': 'if_statement', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'tabular'}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '219']}; {'id': '212', 'type': 'attribute', 'children': ['213', '218']}, {'id': '213', 'type': 'subscript', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '217', 'type': 'string', 'children': [], 'value': "'--blast'"}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'string', 'children': [], 'value': '"3"'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '225']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'is'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '224', 'type': 'None', 'children': []}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '235']}; {'id': '228', 'type': 'attribute', 'children': ['229', '234']}, {'id': '229', 'type': 'subscript', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'-a'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '240', 'type': 'call', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '242', 'type': 'argument_list', 'children': []}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'f_otumap'}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'OtuMap'"}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '252', 'type': 'generator_expression', 'children': ['253', '263']}, {'id': '253', 'type': 'call', 'children': ['254', '261']}; {'id': '254', 'type': 'attribute', 'children': ['255', '260']}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '259', 'type': 'argument_list', 'children': []}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'string', 'children': [], 'value': "'\\t'"}, {'id': '263', 'type': 'for_in_clause', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'f_otumap'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'clusters'}, {'id': '269', 'type': 'dictionary_comprehension', 'children': ['270', '279']}; {'id': '270', 'type': 'pair', 'children': ['271', '274']}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '273', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '274', 'type': 'subscript', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '276', 'type': 'slice', 'children': ['277', '278']}, {'id': '277', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '278', 'type': 'colon', 'children': []}, {'id': '279', 'type': 'for_in_clause', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'f_failure'}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '287', 'type': 'string', 'children': [], 'value': "'FastaForDenovo'"}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'failures'}, {'id': '291', 'type': 'list_comprehension', 'children': ['292', '301']}; {'id': '292', 'type': 'subscript', 'children': ['293', '300']}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': "'>| '"}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '301', 'type': 'for_in_clause', 'children': ['302', '305']}; {'id': '302', 'type': 'pattern_list', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'seq'}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'parse_fasta'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'f_failure'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'smr_files_to_remove'}; {'id': '312', 'type': 'list', 'children': ['313', '318', '323'], 'value': "[app_result['FastaForDenovo'].name,\n app_result['FastaMatches'].name,\n app_result['OtuMap'].name]"}, {'id': '313', 'type': 'attribute', 'children': ['314', '317']}; {'id': '314', 'type': 'subscript', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'FastaForDenovo'"}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '318', 'type': 'attribute', 'children': ['319', '322']}, {'id': '319', 'type': 'subscript', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '321', 'type': 'string', 'children': [], 'value': "'FastaMatches'"}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '323', 'type': 'attribute', 'children': ['324', '327']}; {'id': '324', 'type': 'subscript', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'OtuMap'"}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '328', 'type': 'return_statement', 'children': ['329']}, {'id': '329', 'type': 'expression_list', 'children': ['330', '331', '332']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'clusters'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'failures'}
def sortmerna_ref_cluster(seq_path=None, sortmerna_db=None, refseqs_fp=None, result_path=None, tabular=False, max_e_value=1, similarity=0.97, coverage=0.97, threads=1, best=1, HALT_EXEC=False ): smr = Sortmerna(HALT_EXEC=HALT_EXEC) if seq_path is not None: smr.Parameters['--reads'].on(seq_path) else: raise ValueError("Error: a read file is mandatory input.") if sortmerna_db is not None: smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) else: raise ValueError("Error: an indexed database for reference set %s must" " already exist.\nUse indexdb_rna to index the" " database." % refseqs_fp) if result_path is None: raise ValueError("Error: the result path must be set.") output_dir = dirname(result_path) if output_dir is not None: output_file = join(output_dir, "sortmerna_otus") smr.Parameters['--aligned'].on(output_file) if max_e_value is not None: smr.Parameters['-e'].on(max_e_value) if similarity is not None: smr.Parameters['--id'].on(similarity) if coverage is not None: smr.Parameters['--coverage'].on(coverage) if best is not None: smr.Parameters['--best'].on(best) if tabular: smr.Parameters['--blast'].on("3") if threads is not None: smr.Parameters['-a'].on(threads) app_result = smr() f_otumap = app_result['OtuMap'] rows = (line.strip().split('\t') for line in f_otumap) clusters = {r[0]: r[1:] for r in rows} f_failure = app_result['FastaForDenovo'] failures = [re.split('>| ', label)[0] for label, seq in parse_fasta(f_failure)] smr_files_to_remove = [app_result['FastaForDenovo'].name, app_result['FastaMatches'].name, app_result['OtuMap'].name] return clusters, failures, smr_files_to_remove
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortmerna_map'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20', '23', '26', '29', '32']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq_path'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortmerna_db'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'e_value'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'num_alignments'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'output_sam'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sam_SQ_tags'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'blast_format'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'print_all_reads'}; {'id': '34', 'type': 'True', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36', '50', '63', '72', '87', '98', '112', '138', '151', '159', '170', '186', '202', '218', '234', '244', '254', '264', '274', '284', '290']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42']}, {'id': '37', 'type': 'not_operator', 'children': ['38']}; {'id': '38', 'type': 'parenthesized_expression', 'children': ['39'], 'value': '()'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'or'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'blast_format'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'output_sam'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'raise_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'concatenated_string', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"Either Blast or SAM output alignment "'}, {'id': '49', 'type': 'string', 'children': [], 'value': '"format must be chosen."'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '55']}, {'id': '51', 'type': 'parenthesized_expression', 'children': ['52'], 'value': '()'}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'num_alignments'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'raise_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'concatenated_string', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"Only one of --best or --num_alignments "'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"options must be chosen."'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Sortmerna'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '81']}; {'id': '74', 'type': 'attribute', 'children': ['75', '80']}, {'id': '75', 'type': 'subscript', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'--ref'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '%'}, {'id': '83', 'type': 'string', 'children': [], 'value': '"%s,%s"'}; {'id': '84', 'type': 'tuple', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'refseqs_fp'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sortmerna_db'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '96']}, {'id': '89', 'type': 'attribute', 'children': ['90', '95']}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'--reads'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'seq_path'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'blast_format'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '110']}, {'id': '103', 'type': 'attribute', 'children': ['104', '109']}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'--blast'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'blast_format'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'output_sam'}; {'id': '114', 'type': 'block', 'children': ['115', '125']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '124']}, {'id': '117', 'type': 'attribute', 'children': ['118', '123']}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'--sam'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sam_SQ_tags'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '137']}; {'id': '130', 'type': 'attribute', 'children': ['131', '136']}, {'id': '131', 'type': 'subscript', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'--SQ'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'if_statement', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'print_all_reads'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '150']}, {'id': '143', 'type': 'attribute', 'children': ['144', '149']}; {'id': '144', 'type': 'subscript', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'--print_all_reads'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'output_file'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '158', 'type': 'string', 'children': [], 'value': '"sortmerna_map"'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '168']}, {'id': '161', 'type': 'attribute', 'children': ['162', '167']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'--aligned'"}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'output_file'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'e_value'}, {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '184']}, {'id': '177', 'type': 'attribute', 'children': ['178', '183']}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '182', 'type': 'string', 'children': [], 'value': "'-e'"}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'e_value'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'best'}, {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '200']}, {'id': '193', 'type': 'attribute', 'children': ['194', '199']}; {'id': '194', 'type': 'subscript', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'--best'"}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '202', 'type': 'if_statement', 'children': ['203', '206']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': 'is'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'num_alignments'}, {'id': '205', 'type': 'None', 'children': []}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '216']}, {'id': '209', 'type': 'attribute', 'children': ['210', '215']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'--num_alignments'"}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'num_alignments'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '222']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'is'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '221', 'type': 'None', 'children': []}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '232']}, {'id': '225', 'type': 'attribute', 'children': ['226', '231']}; {'id': '226', 'type': 'subscript', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'-a'"}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '243']}; {'id': '236', 'type': 'attribute', 'children': ['237', '242']}, {'id': '237', 'type': 'subscript', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '241', 'type': 'string', 'children': [], 'value': "'--fastx'"}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'off'}, {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '253']}; {'id': '246', 'type': 'attribute', 'children': ['247', '252']}, {'id': '247', 'type': 'subscript', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '251', 'type': 'string', 'children': [], 'value': "'--otu_map'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'off'}, {'id': '253', 'type': 'argument_list', 'children': []}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '263']}; {'id': '256', 'type': 'attribute', 'children': ['257', '262']}, {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'--de_novo_otu'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'off'}, {'id': '263', 'type': 'argument_list', 'children': []}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '273']}; {'id': '266', 'type': 'attribute', 'children': ['267', '272']}, {'id': '267', 'type': 'subscript', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '271', 'type': 'string', 'children': [], 'value': "'--id'"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'off'}, {'id': '273', 'type': 'argument_list', 'children': []}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '283']}; {'id': '276', 'type': 'attribute', 'children': ['277', '282']}, {'id': '277', 'type': 'subscript', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'smr'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '281', 'type': 'string', 'children': [], 'value': "'--coverage'"}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'off'}, {'id': '283', 'type': 'argument_list', 'children': []}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'smr'}, {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'return_statement', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'app_result'}
def sortmerna_map(seq_path, output_dir, refseqs_fp, sortmerna_db, e_value=1, threads=1, best=None, num_alignments=None, HALT_EXEC=False, output_sam=False, sam_SQ_tags=False, blast_format=3, print_all_reads=True, ): if not (blast_format or output_sam): raise ValueError("Either Blast or SAM output alignment " "format must be chosen.") if (best and num_alignments): raise ValueError("Only one of --best or --num_alignments " "options must be chosen.") smr = Sortmerna(HALT_EXEC=HALT_EXEC) smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db)) smr.Parameters['--reads'].on(seq_path) if blast_format: smr.Parameters['--blast'].on(blast_format) if output_sam: smr.Parameters['--sam'].on() if sam_SQ_tags: smr.Parameters['--SQ'].on() if print_all_reads: smr.Parameters['--print_all_reads'].on() output_file = join(output_dir, "sortmerna_map") smr.Parameters['--aligned'].on(output_file) if e_value is not None: smr.Parameters['-e'].on(e_value) if best is not None: smr.Parameters['--best'].on(best) if num_alignments is not None: smr.Parameters['--num_alignments'].on(num_alignments) if threads is not None: smr.Parameters['-a'].on(threads) smr.Parameters['--fastx'].off() smr.Parameters['--otu_map'].off() smr.Parameters['--de_novo_otu'].off() smr.Parameters['--id'].off() smr.Parameters['--coverage'].off() app_result = smr() return app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_dict_values_sorted_by_key'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dictionary'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '26']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '18']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dictionary'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'yield', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'}
def _dict_values_sorted_by_key(dictionary): for _, value in sorted(dictionary.iteritems(), key=operator.itemgetter(0)): yield value
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '52']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'uclust_cluster_from_sorted_fasta_filepath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '49']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'uc_save_filepath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'percent_ID'}; {'id': '10', 'type': 'float', 'children': [], 'value': '0.97'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_accepts'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_rejects'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'stepwords'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'word_length'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'optimal'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'exact'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'enable_rev_strand_matching'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'stable_sort'}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'gettempdir'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'default_parameter', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '51', 'type': 'False', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53', '57', '78', '100', '113', '126', '139', '152', '165', '179', '192', '205', '218']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'uc_save_filepath'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '60']}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '72', '75']}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'uclust_clusters'"}, {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'.uc'"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '81', 'type': 'dictionary', 'children': ['82', '85', '88', '91', '94', '97']}; {'id': '82', 'type': 'pair', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'--id'"}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'percent_ID'}, {'id': '85', 'type': 'pair', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'--maxaccepts'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'max_accepts'}; {'id': '88', 'type': 'pair', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'--maxrejects'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'max_rejects'}, {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'--stepwords'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'stepwords'}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'--w'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'word_length'}, {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'--tmpdir'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Uclust'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107', '110']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'TmpDir'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '113', 'type': 'if_statement', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'enable_rev_strand_matching'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '125']}; {'id': '118', 'type': 'attribute', 'children': ['119', '124']}, {'id': '119', 'type': 'subscript', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'--rev'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'optimal'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '138']}, {'id': '131', 'type': 'attribute', 'children': ['132', '137']}; {'id': '132', 'type': 'subscript', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'--optimal'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'if_statement', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'exact'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '151']}; {'id': '144', 'type': 'attribute', 'children': ['145', '150']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'--exact'"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '164']}, {'id': '157', 'type': 'attribute', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'--usersort'"}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'if_statement', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '177']}; {'id': '170', 'type': 'attribute', 'children': ['171', '176']}, {'id': '171', 'type': 'subscript', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'--lib'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}, {'id': '179', 'type': 'if_statement', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '191']}; {'id': '184', 'type': 'attribute', 'children': ['185', '190']}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'--libonly'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'if_statement', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'stable_sort'}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '204']}, {'id': '197', 'type': 'attribute', 'children': ['198', '203']}; {'id': '198', 'type': 'subscript', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'--stable_sort'"}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '204', 'type': 'argument_list', 'children': []}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'dictionary', 'children': ['212', '215']}; {'id': '212', 'type': 'pair', 'children': ['213', '214']}, {'id': '213', 'type': 'string', 'children': [], 'value': "'--input'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '215', 'type': 'pair', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': "'--uc'"}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '218', 'type': 'return_statement', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'app_result'}
def uclust_cluster_from_sorted_fasta_filepath( fasta_filepath, uc_save_filepath=None, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, stable_sort=False, tmp_dir=gettempdir(), HALT_EXEC=False): output_filepath = uc_save_filepath if not output_filepath: _, output_filepath = mkstemp(dir=tmp_dir, prefix='uclust_clusters', suffix='.uc') params = {'--id': percent_ID, '--maxaccepts': max_accepts, '--maxrejects': max_rejects, '--stepwords': stepwords, '--w': word_length, '--tmpdir': tmp_dir} app = Uclust(params, TmpDir=tmp_dir, HALT_EXEC=HALT_EXEC) if enable_rev_strand_matching: app.Parameters['--rev'].on() if optimal: app.Parameters['--optimal'].on() if exact: app.Parameters['--exact'].on() if suppress_sort: app.Parameters['--usersort'].on() if subject_fasta_filepath: app.Parameters['--lib'].on(subject_fasta_filepath) if suppress_new_clusters: app.Parameters['--libonly'].on() if stable_sort: app.Parameters['--stable_sort'].on() app_result = app({'--input': fasta_filepath, '--uc': output_filepath}) return app_result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '59']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_clusters_from_fasta_filepath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39', '42', '45', '48', '53', '56']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'original_fasta_path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'percent_ID'}; {'id': '8', 'type': 'float', 'children': [], 'value': '0.97'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'max_accepts'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'max_rejects'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'stepwords'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'word_length'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'optimal'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'exact'}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}, {'id': '29', 'type': 'False', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'enable_rev_strand_matching'}, {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}, {'id': '41', 'type': 'False', 'children': []}; {'id': '42', 'type': 'default_parameter', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'return_cluster_maps'}; {'id': '44', 'type': 'False', 'children': []}, {'id': '45', 'type': 'default_parameter', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stable_sort'}, {'id': '47', 'type': 'False', 'children': []}; {'id': '48', 'type': 'default_parameter', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'gettempdir'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'default_parameter', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'save_uc_files'}, {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'default_parameter', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '58', 'type': 'False', 'children': []}, {'id': '59', 'type': 'block', 'children': ['60', '64', '68', '72', '87', '104', '108', '112', '116', '120', '247', '260', '270']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'fasta_output_filepath'}, {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'uc_output_filepath'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cd_hit_filepath'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '82']}, {'id': '73', 'type': 'boolean_operator', 'children': ['74', '75'], 'value': 'and'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'augmented_assignment', 'children': ['85', '86'], 'value': '+='}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '87', 'type': 'if_statement', 'children': ['88', '89', '98']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'save_uc_files'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'uc_save_filepath'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get_output_filepaths'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'output_dir'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'original_fasta_path'}; {'id': '98', 'type': 'else_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'uc_save_filepath'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sorted_fasta_filepath'}, {'id': '107', 'type': 'string', 'children': [], 'value': '""'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'uc_filepath'}, {'id': '111', 'type': 'string', 'children': [], 'value': '""'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'clstr_filepath'}, {'id': '115', 'type': 'string', 'children': [], 'value': '""'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}, {'id': '119', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '120', 'type': 'try_statement', 'children': ['121', '216', '232']}, {'id': '121', 'type': 'block', 'children': ['122', '161', '211']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '125', '151']}, {'id': '123', 'type': 'not_operator', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}, {'id': '125', 'type': 'block', 'children': ['126', '136', '144']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort_fasta'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'uclust_fasta_sort_from_filepath'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'fasta_output_filepath'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sorted_fasta_filepath'}, {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sort_fasta'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'Output'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'sorted_fasta_filepath'}, {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153', '157']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sort_fasta'}; {'id': '156', 'type': 'None', 'children': []}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sorted_fasta_filepath'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'uclust_cluster'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'uclust_cluster_from_sorted_fasta_filepath'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169', '172', '175', '178', '181', '184', '187', '190', '193', '196', '199', '202', '205', '208']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted_fasta_filepath'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'uc_save_filepath'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'percent_ID'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'percent_ID'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'max_accepts'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'max_accepts'}, {'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'max_rejects'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'max_rejects'}; {'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'stepwords'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'stepwords'}, {'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'word_length'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'word_length'}; {'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'optimal'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'optimal'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'exact'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'exact'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'suppress_sort'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'enable_rev_strand_matching'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'enable_rev_strand_matching'}; {'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'subject_fasta_filepath'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'suppress_new_clusters'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stable_sort'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'stable_sort'}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'remove_files'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}; {'id': '216', 'type': 'except_clause', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ApplicationError'}; {'id': '218', 'type': 'block', 'children': ['219', '224']}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'remove_files'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}; {'id': '224', 'type': 'raise_statement', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'ApplicationError'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'concatenated_string', 'children': ['229', '230', '231']}, {'id': '229', 'type': 'string', 'children': [], 'value': "'Error running uclust. Possible causes are '"}; {'id': '230', 'type': 'string', 'children': [], 'value': "'unsupported version (current supported version is v1.2.22) is installed or '"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'improperly formatted input file was provided'"}; {'id': '232', 'type': 'except_clause', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ApplicationNotFoundError'}; {'id': '234', 'type': 'block', 'children': ['235', '240']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'remove_files'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'files_to_remove'}; {'id': '240', 'type': 'raise_statement', 'children': ['241']}, {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ApplicationNotFoundError'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '246'], 'value': '+'}, {'id': '245', 'type': 'string', 'children': [], 'value': "'uclust not found, is it properly '"}; {'id': '246', 'type': 'string', 'children': [], 'value': "'installed?'"}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '253', '254']}, {'id': '249', 'type': 'pattern_list', 'children': ['250', '251', '252']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'clusters'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'failures'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'seeds'}, {'id': '253', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'clusters_from_uc_file'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'uclust_cluster'}, {'id': '259', 'type': 'string', 'children': [], 'value': "'ClusterFile'"}; {'id': '260', 'type': 'if_statement', 'children': ['261', '263']}, {'id': '261', 'type': 'not_operator', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'save_uc_files'}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'uclust_cluster'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'cleanUp'}, {'id': '269', 'type': 'argument_list', 'children': []}; {'id': '270', 'type': 'if_statement', 'children': ['271', '272', '278']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'return_cluster_maps'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'return_statement', 'children': ['274']}; {'id': '274', 'type': 'expression_list', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'clusters'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'failures'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'seeds'}; {'id': '278', 'type': 'else_clause', 'children': ['279']}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'return_statement', 'children': ['281']}, {'id': '281', 'type': 'expression_list', 'children': ['282', '287', '288']}; {'id': '282', 'type': 'call', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'clusters'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '286', 'type': 'argument_list', 'children': []}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'failures'}
def get_clusters_from_fasta_filepath( fasta_filepath, original_fasta_path, percent_ID=0.97, max_accepts=1, max_rejects=8, stepwords=8, word_length=8, optimal=False, exact=False, suppress_sort=False, output_dir=None, enable_rev_strand_matching=False, subject_fasta_filepath=None, suppress_new_clusters=False, return_cluster_maps=False, stable_sort=False, tmp_dir=gettempdir(), save_uc_files=True, HALT_EXEC=False): fasta_output_filepath = None uc_output_filepath = None cd_hit_filepath = None if output_dir and not output_dir.endswith('/'): output_dir += '/' if save_uc_files: uc_save_filepath = get_output_filepaths( output_dir, original_fasta_path) else: uc_save_filepath = None sorted_fasta_filepath = "" uc_filepath = "" clstr_filepath = "" files_to_remove = [] try: if not suppress_sort: sort_fasta = uclust_fasta_sort_from_filepath(fasta_filepath, output_filepath=fasta_output_filepath) sorted_fasta_filepath = sort_fasta['Output'].name files_to_remove.append(sorted_fasta_filepath) else: sort_fasta = None sorted_fasta_filepath = fasta_filepath uclust_cluster = uclust_cluster_from_sorted_fasta_filepath( sorted_fasta_filepath, uc_save_filepath, percent_ID=percent_ID, max_accepts=max_accepts, max_rejects=max_rejects, stepwords=stepwords, word_length=word_length, optimal=optimal, exact=exact, suppress_sort=suppress_sort, enable_rev_strand_matching=enable_rev_strand_matching, subject_fasta_filepath=subject_fasta_filepath, suppress_new_clusters=suppress_new_clusters, stable_sort=stable_sort, tmp_dir=tmp_dir, HALT_EXEC=HALT_EXEC) remove_files(files_to_remove) except ApplicationError: remove_files(files_to_remove) raise ApplicationError('Error running uclust. Possible causes are ' 'unsupported version (current supported version is v1.2.22) is installed or ' 'improperly formatted input file was provided') except ApplicationNotFoundError: remove_files(files_to_remove) raise ApplicationNotFoundError('uclust not found, is it properly ' + 'installed?') clusters, failures, seeds = \ clusters_from_uc_file(uclust_cluster['ClusterFile']) if not save_uc_files: uclust_cluster.cleanUp() if return_cluster_maps: return clusters, failures, seeds else: return clusters.values(), failures, seeds
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ls'}, {'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': 'startswith'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '20', '29', '48']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'\n List all cubes available to the calling client.\n :param startswith: string to use in a simple "startswith" query filter\n :returns list: sorted list of cube names\n \'\'\''}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '%'}; {'id': '18', 'type': 'string', 'children': [], 'value': '\'Listing cubes starting with "%s")\''}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'unicode'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'boolean_operator', 'children': ['27', '28'], 'value': 'or'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '28', 'type': 'string', 'children': [], 'value': "''"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'generator_expression', 'children': ['35', '36', '41']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'db_tables'}, {'id': '41', 'type': 'if_clause', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'tables'}
def ls(self, startswith=None): ''' List all cubes available to the calling client. :param startswith: string to use in a simple "startswith" query filter :returns list: sorted list of cube names ''' logger.info('Listing cubes starting with "%s")' % startswith) startswith = unicode(startswith or '') tables = sorted(name for name in self.db_tables if name.startswith(startswith)) return tables
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '35']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch_sort_by_abundance'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sizein'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sizeout'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'minsize'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"abundance_sort.log"'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'usersort'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36', '54', '71', '75', '88', '101', '115', '128', '141', '151', '161', '180']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '39']}, {'id': '37', 'type': 'not_operator', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '51']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'usearch_abundance_sorted'"}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'.fasta'"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '70'], 'value': '+'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '+'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'}; {'id': '64', 'type': 'string', 'children': [], 'value': '"minsize_"'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'minsize'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '74', 'type': 'dictionary', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'Usearch'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'usersort'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '100']}, {'id': '93', 'type': 'attribute', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'--usersort'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'minsize'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '113']}; {'id': '106', 'type': 'attribute', 'children': ['107', '112']}, {'id': '107', 'type': 'subscript', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'--minsize'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'minsize'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sizein'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '127']}; {'id': '120', 'type': 'attribute', 'children': ['121', '126']}, {'id': '121', 'type': 'subscript', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'--sizein'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '127', 'type': 'argument_list', 'children': []}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sizeout'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '140']}, {'id': '133', 'type': 'attribute', 'children': ['134', '139']}; {'id': '134', 'type': 'subscript', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Parameters'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'--sizeout'"}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'on'}; {'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': 'data'}; {'id': '144', 'type': 'dictionary', 'children': ['145', '148']}, {'id': '145', 'type': 'pair', 'children': ['146', '147']}; {'id': '146', 'type': 'string', 'children': [], 'value': "'--sortsize'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}; {'id': '148', 'type': 'pair', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': "'--output'"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '154']}; {'id': '152', 'type': 'not_operator', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'--log'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '161', 'type': 'try_statement', 'children': ['162', '170']}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '170', 'type': 'except_clause', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ApplicationError'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'raise_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'No data following filter steps, please check '"}, {'id': '179', 'type': 'string', 'children': [], 'value': "'parameter settings for usearch_qf.'"}; {'id': '180', 'type': 'return_statement', 'children': ['181']}, {'id': '181', 'type': 'expression_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}
def usearch_sort_by_abundance( fasta_filepath, output_filepath=None, sizein=True, sizeout=True, minsize=0, log_name="abundance_sort.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_abundance_sorted', suffix='.fasta') log_filepath = join( working_dir, "minsize_" + str(minsize) + "_" + log_name) params = {} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() if minsize: app.Parameters['--minsize'].on(minsize) if sizein: app.Parameters['--sizein'].on() if sizeout: app.Parameters['--sizeout'].on() data = {'--sortsize': fasta_filepath, '--output': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath try: app_result = app(data) except ApplicationError: raise ValueError('No data following filter steps, please check ' + 'parameter settings for usearch_qf.') return app_result, output_filepath
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '47']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'usearch_cluster_error_correction'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'percent_id_err'}, {'id': '13', 'type': 'float', 'children': [], 'value': '0.97'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sizein'}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sizeout'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'slots'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '16769023'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '64'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'log_name'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"usearch_cluster_err_corrected.log"'}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'usersort'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'save_intermediate_files'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48', '66', '74', '96', '109', '122', '132', '142', '151', '158']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '51']}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'pattern_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'usearch_cluster_err_corrected'"}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'.fasta'"}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'log_name'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '77', 'type': 'dictionary', 'children': ['78', '81', '84', '87', '90', '93']}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'--sizein'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sizein'}, {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'--sizeout'"}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sizeout'}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'--id'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'percent_id_err'}, {'id': '87', 'type': 'pair', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'--w'"}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '90', 'type': 'pair', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': "'--slots'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'slots'}, {'id': '93', 'type': 'pair', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'--maxrejects'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'maxrejects'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Usearch'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '106']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'WorkingDir'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'HALT_EXEC'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'usersort'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '121']}; {'id': '114', 'type': 'attribute', 'children': ['115', '120']}, {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'Parameters'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'--usersort'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'on'}, {'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': 'data'}, {'id': '125', 'type': 'dictionary', 'children': ['126', '129']}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'--cluster'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fasta_filepath'}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'--consout'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '135']}, {'id': '133', 'type': 'not_operator', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'remove_usearch_logs'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '141']}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'--log'"}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'log_filepath'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '150']}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'--uc'"}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'output_uc_filepath'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'app_result'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '158', 'type': 'return_statement', 'children': ['159']}, {'id': '159', 'type': 'expression_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'app_result'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'output_filepath'}
def usearch_cluster_error_correction( fasta_filepath, output_filepath=None, output_uc_filepath=None, percent_id_err=0.97, sizein=True, sizeout=True, w=64, slots=16769023, maxrejects=64, log_name="usearch_cluster_err_corrected.log", usersort=False, HALT_EXEC=False, save_intermediate_files=False, remove_usearch_logs=False, working_dir=None): if not output_filepath: _, output_filepath = mkstemp(prefix='usearch_cluster_err_corrected', suffix='.fasta') log_filepath = join(working_dir, log_name) params = {'--sizein': sizein, '--sizeout': sizeout, '--id': percent_id_err, '--w': w, '--slots': slots, '--maxrejects': maxrejects} app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC) if usersort: app.Parameters['--usersort'].on() data = {'--cluster': fasta_filepath, '--consout': output_filepath } if not remove_usearch_logs: data['--log'] = log_filepath if output_uc_filepath: data['--uc'] = output_uc_filepath app_result = app(data) return app_result, output_filepath