sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_as_json'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '11', '16', '19']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '10', 'type': 'string', 'children': [], 'value': "'data.json'"},{'id': '11', 'type': 'typed_default_parameter', 'children': ['12', '13', '15']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '13', 'type': 'type', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'no_duplicate'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '21', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '22', 'type': 'block', 'children': ['23', '48', '64', '76']},{'id': '23', 'type': 'if_statement', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '25', 'type': 'block', 'children': ['26', '32']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '=='},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '31', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '45']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '48', 'type': 'if_statement', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'no_duplicate'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '54', 'type': 'list_comprehension', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '60']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'ensure_ascii'},{'id': '75', 'type': 'False', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '84']},{'id': '78', 'type': 'attribute', 'children': ['79', '83']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'Path'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'write_text'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '88', 'type': 'string', 'children': [], 'value': "'utf-8'"}
def save_as_json(total: list, name='data.json', sort_by: str = None, no_duplicate=False, order='asc'): if sort_by: reverse = order == 'desc' total = sorted(total, key=itemgetter(sort_by), reverse=reverse) if no_duplicate: total = [key for key, _ in groupby(total)] data = json.dumps(total, ensure_ascii=False) Path(name).write_text(data, encoding='utf-8')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '7', 'type': 'block', 'children': ['8', '16', '28', '44']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'token'},{'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': 'Token'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_filter_order'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'tuple', 'children': ['25', '26', '27']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_filter_order'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '38', 'type': 'lambda', 'children': ['39', '41']},{'id': '39', 'type': 'lambda_parameters', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'token'}
def register(self, func, order): token = self.Token() self._filter_order.append((order, token, func)) self._filter_order.sort(key=lambda x: x[0]) return token
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_features'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '6', 'type': 'block', 'children': ['7', '19', '25', '49']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '10', 'type': 'yield', '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': '_disco'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'query_info'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '30']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'features'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'try_statement', 'children': ['32', '45']},{'id': '32', 'type': 'block', 'children': ['33']},{'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': 'result'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'pubsub_xso'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Feature'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'feature'},{'id': '45', 'type': 'except_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'continue_statement', 'children': []},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'result'}
def get_features(self, jid): response = yield from self._disco.query_info(jid) result = set() for feature in response.features: try: result.add(pubsub_xso.Feature(feature)) except ValueError: continue return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'block', 'children': ['7', '19']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'locate_keys'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '18', 'type': 'False', 'children': []},{'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': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'}
def intersect(self, other): loc = self.locate_keys(other, strict=False) return self.compress(loc, axis=0)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'locate_intersection_ranges'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '7', 'type': 'block', 'children': ['8', '16', '24', '30', '40', '53', '59', '75', '98']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'asarray_ndim'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'asarray_ndim'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'check_dim0_aligned'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'start_indices'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stop_indices'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'side'},{'id': '52', 'type': 'string', 'children': [], 'value': "'right'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'loc_ranges'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '<'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'start_indices'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'stop_indices'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '75', 'type': 'for_statement', 'children': ['76', '79', '88']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '81', 'type': 'argument_list', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'start_indices'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'loc_ranges'},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'stop_indices'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'loc_ranges'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '97']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '93', 'type': 'slice', 'children': ['94', '95', '96']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'colon', 'children': []},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '97', 'type': 'True', 'children': []},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'expression_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'loc_ranges'}
def locate_intersection_ranges(self, starts, stops): starts = asarray_ndim(starts, 1) stops = asarray_ndim(stops, 1) check_dim0_aligned(starts, stops) start_indices = np.searchsorted(self, starts) stop_indices = np.searchsorted(self, stops, side='right') loc_ranges = start_indices < stop_indices loc = np.zeros(self.shape, dtype=np.bool) for i, j in zip(start_indices[loc_ranges], stop_indices[loc_ranges]): loc[i:j] = True return loc, loc_ranges
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'locate_ranges'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '23', '46']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '16']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'found'},{'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': 'locate_intersection_ranges'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '23', 'type': 'if_statement', 'children': ['24', '33']},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'and'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '~'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'found'},{'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': 'KeyError'},{'id': '37', 'type': 'argument_list', 'children': ['38', '42']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '40', 'type': 'unary_operator', 'children': ['41'], 'value': '~'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '~'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'found'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'loc'}
def locate_ranges(self, starts, stops, strict=True): loc, found = self.locate_intersection_ranges(starts, stops) if strict and np.any(~found): raise KeyError(starts[~found], stops[~found]) return loc
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersect_ranges'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '7', 'type': 'block', 'children': ['8', '21']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'loc'},{'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': 'locate_ranges'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'starts'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'stops'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'compress'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'}
def intersect_ranges(self, starts, stops): loc = self.locate_ranges(starts, stops, strict=False) return self.compress(loc, axis=0)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_gff3'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15', '19', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '21', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '51']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'gff3_to_recarray'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '36', '39', '42', '45', '48']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55', '58']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'None', 'children': []},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'FeatureTable'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '67', 'type': 'False', 'children': []}
def from_gff3(path, attributes=None, region=None, score_fill=-1, phase_fill=-1, attributes_fill='.', dtype=None): a = gff3_to_recarray(path, attributes=attributes, region=region, score_fill=score_fill, phase_fill=phase_fill, attributes_fill=attributes_fill, dtype=dtype) if a is None: return None else: return FeatureTable(a, copy=False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_gff3'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15', '19', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '21', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '24', 'type': 'string', 'children': [], 'value': "'tabix'"},{'id': '25', 'type': 'block', 'children': ['26', '75', '142']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '38']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '38', 'type': 'if_statement', 'children': ['39', '46', '63']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '43', 'type': 'tuple', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'if_statement', 'children': ['48', '57']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '53'], 'value': '!='},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'number of fills does not match attributes'"},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '71'], 'value': '*'},{'id': '69', 'type': 'list', 'children': ['70'], 'value': '[attributes_fill]'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '75', 'type': 'if_statement', 'children': ['76', '79', '103', '130']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '87']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '83', 'type': 'list', 'children': ['84', '85', '86'], 'value': '[tabix, path, region]'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '90', 'type': 'attribute', 'children': ['91', '102']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '103', 'type': 'elif_clause', 'children': ['104', '117']},{'id': '104', 'type': 'boolean_operator', 'children': ['105', '111'], 'value': 'or'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': "'.gz'"},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'string', 'children': [], 'value': "'.bgz'"},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'gzip'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '129', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '130', 'type': 'else_clause', 'children': ['131']},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '141', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '142', 'type': 'try_statement', 'children': ['143', '338']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'for_statement', 'children': ['145', '146', '147']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '147', 'type': 'block', 'children': ['148', '156']},{'id': '148', 'type': 'if_statement', 'children': ['149', '154']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '=='},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'string', 'children': [], 'value': "b'>'"},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'return_statement', 'children': []},{'id': '156', 'type': 'if_statement', 'children': ['157', '170', '177']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '161', '164'], 'value': '=='},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'ERROR', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': "b'\\t'"},{'id': '170', 'type': 'ERROR', 'children': ['171']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '176'], 'value': '=='},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '176', 'type': 'integer', 'children': [], 'value': '9'},{'id': '177', 'type': 'block', 'children': ['178', '191', '198', '205', '223', '241', '285', '297', '335']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '190']},{'id': '180', 'type': 'pattern_list', 'children': ['181', '182', '183', '184', '185', '186', '187', '188', '189']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'fseqid'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fsource'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'fstart'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'fend'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'fstrand'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'fattrs'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'fstart'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'fstart'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'fend'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'fend'},{'id': '205', 'type': 'if_statement', 'children': ['206', '209', '214']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '208', 'type': 'string', 'children': [], 'value': "b'.'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '214', 'type': 'else_clause', 'children': ['215']},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '223', 'type': 'if_statement', 'children': ['224', '227', '232']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': '=='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '226', 'type': 'string', 'children': [], 'value': "b'.'"},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '241', 'type': 'if_statement', 'children': ['242', '244']},{'id': '242', 'type': 'not_operator', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'PY2'},{'id': '244', 'type': 'block', 'children': ['245', '253', '261', '269', '277']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'fseqid'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'fseqid'},{'id': '252', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'fsource'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'fsource'},{'id': '260', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '268', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'fstrand'},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'fstrand'},{'id': '276', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'fattrs'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'fattrs'},{'id': '284', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '288', 'type': 'tuple', 'children': ['289', '290', '291', '292', '293', '294', '295', '296']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'fseqid'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'fsource'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'fstart'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'fend'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'fscore'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'fstrand'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'fphase'},{'id': '297', 'type': 'if_statement', 'children': ['298', '301']},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '300'], 'value': 'is'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '300', 'type': 'None', 'children': []},{'id': '301', 'type': 'block', 'children': ['302', '309', '331']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'dattrs'},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'gff3_parse_attributes'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'fattrs'},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'vattrs'},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '314', 'type': 'generator_expression', 'children': ['315', '322']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'dattrs'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '322', 'type': 'for_in_clause', 'children': ['323', '326']},{'id': '323', 'type': 'pattern_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '326', 'type': 'call', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '328', 'type': 'argument_list', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'augmented_assignment', 'children': ['333', '334'], 'value': '+='},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'vattrs'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'yield', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '338', 'type': 'finally_clause', 'children': ['339']},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'buffer'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '345', 'type': 'argument_list', 'children': []}
def iter_gff3(path, attributes=None, region=None, score_fill=-1, phase_fill=-1, attributes_fill='.', tabix='tabix'): if attributes is not None: attributes = list(attributes) if isinstance(attributes_fill, (list, tuple)): if len(attributes) != len(attributes_fill): raise ValueError('number of fills does not match attributes') else: attributes_fill = [attributes_fill] * len(attributes) if region is not None: cmd = [tabix, path, region] buffer = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout elif path.endswith('.gz') or path.endswith('.bgz'): buffer = gzip.open(path, mode='rb') else: buffer = open(path, mode='rb') try: for line in buffer: if line[0] == b'>': return if line[0] == b' continue vals = line.split(b'\t') if len(vals) == 9: fseqid, fsource, ftype, fstart, fend, fscore, fstrand, fphase, fattrs = vals fstart = int(fstart) fend = int(fend) if fscore == b'.': fscore = score_fill else: fscore = float(fscore) if fphase == b'.': fphase = phase_fill else: fphase = int(fphase) if not PY2: fseqid = str(fseqid, 'ascii') fsource = str(fsource, 'ascii') ftype = str(ftype, 'ascii') fstrand = str(fstrand, 'ascii') fattrs = str(fattrs, 'ascii') rec = (fseqid, fsource, ftype, fstart, fend, fscore, fstrand, fphase) if attributes is not None: dattrs = gff3_parse_attributes(fattrs) vattrs = tuple( dattrs.get(k, f) for k, f in zip(attributes, attributes_fill) ) rec += vattrs yield rec finally: buffer.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gff3_to_recarray'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15', '19', '22', '25']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '21', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '24', 'type': 'string', 'children': [], 'value': "'tabix'"},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29', '57', '63', '112', '126']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'recs'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'iter_gff3'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '42', '45', '48', '51', '54']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '57', 'type': 'if_statement', 'children': ['58', '60']},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'recs'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'block', 'children': ['68', '96']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '71', 'type': 'list', 'children': ['72', '75', '78', '81', '84', '87', '90', '93'], 'value': "[('seqid', object),\n ('source', object),\n ('type', object),\n ('start', int),\n ('end', int),\n ('score', float),\n ('strand', object),\n ('phase', int)]"},{'id': '72', 'type': 'tuple', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'seqid'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '75', 'type': 'tuple', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '78', 'type': 'tuple', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '81', 'type': 'tuple', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '84', 'type': 'tuple', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '87', 'type': 'tuple', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '90', 'type': 'tuple', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': "'strand'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '93', 'type': 'tuple', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'phase'"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '96', 'type': 'if_statement', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'for_statement', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'tuple', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'object'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'fromrecords'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'recs'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'a'}
def gff3_to_recarray(path, attributes=None, region=None, score_fill=-1, phase_fill=-1, attributes_fill='.', tabix='tabix', dtype=None): recs = list(iter_gff3(path, attributes=attributes, region=region, score_fill=score_fill, phase_fill=phase_fill, attributes_fill=attributes_fill, tabix=tabix)) if not recs: return None if dtype is None: dtype = [('seqid', object), ('source', object), ('type', object), ('start', int), ('end', int), ('score', float), ('strand', object), ('phase', int)] if attributes: for n in attributes: dtype.append((n, object)) a = np.rec.fromrecords(recs, dtype=dtype) return a
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gff3_to_dataframe'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '15', '19', '22', '25']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '13', 'type': 'unary_operator', 'children': ['14'], 'value': '-'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'},{'id': '18', 'type': 'integer', 'children': [], 'value': '1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '21', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '24', 'type': 'string', 'children': [], 'value': "'tabix'"},{'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'block', 'children': ['28', '31', '59', '71', '81', '97']},{'id': '28', 'type': 'import_statement', 'children': ['29']},{'id': '29', 'type': 'dotted_name', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'recs'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'iter_gff3'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '44', '47', '50', '53', '56']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'region'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'score_fill'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'phase_fill'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'attributes_fill'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tabix'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '62', 'type': 'list', 'children': ['63', '64', '65', '66', '67', '68', '69', '70'], 'value': "['seqid', 'source', 'type', 'start', 'end', 'score', 'strand', 'phase']"},{'id': '63', 'type': 'string', 'children': [], 'value': "'seqid'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'source'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '67', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '68', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '69', 'type': 'string', 'children': [], 'value': "'strand'"},{'id': '70', 'type': 'string', 'children': [], 'value': "'phase'"},{'id': '71', 'type': 'if_statement', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'augmented_assignment', 'children': ['76', '77'], 'value': '+='},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'from_records'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '95']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'recs'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '95', 'type': 'dictionary_splat', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'df'}
def gff3_to_dataframe(path, attributes=None, region=None, score_fill=-1, phase_fill=-1, attributes_fill='.', tabix='tabix', **kwargs): import pandas recs = list(iter_gff3(path, attributes=attributes, region=region, score_fill=score_fill, phase_fill=phase_fill, attributes_fill=attributes_fill, tabix=tabix)) columns = ['seqid', 'source', 'type', 'start', 'end', 'score', 'strand', 'phase'] if attributes: columns += list(attributes) df = pandas.DataFrame.from_records(recs, columns=columns, **kwargs) return df
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'voight_painting'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '5', 'type': 'block', 'children': ['6', '21', '35', '49', '57', '70', '85']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'HaplotypeArray'},{'id': '11', 'type': 'argument_list', 'children': ['12', '18']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'if_statement', 'children': ['22', '29']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '28'], 'value': '>'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'only biallelic variants are supported'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '42'], 'value': '<'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'NotImplementedError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': "'missing calls are not supported'"},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'prefix_argsort'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'take'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'painting'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'paint_shared_prefixes'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'memoryview_safe'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'asarray'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'expression_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'painting'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'indices'}
def voight_painting(h): h = HaplotypeArray(np.asarray(h), copy=False) if h.max() > 1: raise NotImplementedError('only biallelic variants are supported') if h.min() < 0: raise NotImplementedError('missing calls are not supported') indices = h.prefix_argsort() h = np.take(h, indices, axis=1) painting = paint_shared_prefixes(memoryview_safe(np.asarray(h))) return painting, indices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_model_perms'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '5', 'type': 'block', 'children': ['6', '14', '22', '34', '50', '68']},{'id': '6', 'type': 'import_from_statement', 'children': ['7', '12']},{'id': '7', 'type': 'dotted_name', 'children': ['8', '9', '10', '11']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'django'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'contrib'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Permission'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'app_label'},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'app_label'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '25', 'type': 'call', 'children': ['26', '33']},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'object_name'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Permission'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'content_type__app_label'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'app_label'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'content_type__model'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'model_name'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'perms'},{'id': '53', 'type': 'generator_expression', 'children': ['54', '61']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': "'%s.%s'"},{'id': '56', 'type': 'tuple', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'app_label'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'codename'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'qs'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'perms'}
def get_model_perms(model): from django.contrib.auth.models import Permission app_label = model._meta.app_label model_name = model._meta.object_name.lower() qs = Permission.objects.filter(content_type__app_label=app_label, content_type__model=model_name) perms = ('%s.%s' % (app_label, p.codename) for p in qs.iterator()) return set(perms)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_trigger_set'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'triggers'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'exclude_previous'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'say'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '24', '28', '163', '185']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'say'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'say'},{'id': '20', 'type': 'lambda', 'children': ['21', '23']},{'id': '21', 'type': 'lambda_parameters', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'trigger_object_list'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'for_statement', 'children': ['29', '32', '36']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'trig'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'triggers'},{'id': '36', 'type': 'block', 'children': ['37', '47', '53', '71', '86', '98', '150']},{'id': '37', 'type': 'if_statement', 'children': ['38', '45']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '40'], 'value': 'and'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'exclude_previous'},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'trig'},{'id': '43', 'type': 'integer', 'children': [], 'value': '1'},{'id': '44', 'type': 'string', 'children': [], 'value': '"previous"'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'continue_statement', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'trig'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '58', 'type': 'expression_list', 'children': ['59', '70']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'RE'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'trig'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'if_statement', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'match'},{'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': 'weight'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'RE'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '98', 'type': 'if_statement', 'children': ['99', '100', '142']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '100', 'type': 'block', 'children': ['101', '113', '123']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'say'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '+'},{'id': '118', 'type': 'string', 'children': [], 'value': '"\\t\\t\\tTrigger belongs to a topic which inherits other topics: level="'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '130']},{'id': '125', 'type': 'subscript', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'triggers'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '136', 'type': 'argument_list', 'children': ['137', '140', '141']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'RE'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '140', 'type': 'string', 'children': [], 'value': '""'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'maxsize'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'trigger_object_list'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'TriggerObj'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161', '162']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'inherit'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sorted_list'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'trigger_object_list'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177', '178', '179', '180', '181', '182', '183', '184']},{'id': '175', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '176', 'type': 'string', 'children': [], 'value': "'inherit'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'is_empty'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '179', 'type': 'string', 'children': [], 'value': "'pound'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'under'"},{'id': '181', 'type': 'string', 'children': [], 'value': "'option'"},{'id': '182', 'type': 'string', 'children': [], 'value': "'wordcount'"},{'id': '183', 'type': 'string', 'children': [], 'value': "'len'"},{'id': '184', 'type': 'string', 'children': [], 'value': "'alphabet'"},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'list_comprehension', 'children': ['187', '192']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'triggers'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '192', 'type': 'for_in_clause', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}
def sort_trigger_set(triggers, exclude_previous=True, say=None): if say is None: say = lambda x: x trigger_object_list = [] for index, trig in enumerate(triggers): if exclude_previous and trig[1]["previous"]: continue pattern = trig[0] match, weight = re.search(RE.weight, trig[0]), 0 if match: weight = int(match.group(1)) match = re.search(RE.inherit, pattern) if match: inherit = int(match.group(1)) say("\t\t\tTrigger belongs to a topic which inherits other topics: level=" + str(inherit)) triggers[index][0] = pattern = re.sub(RE.inherit, "", pattern) else: inherit = sys.maxsize trigger_object_list.append(TriggerObj(pattern, index, weight, inherit)) sorted_list = sorted(trigger_object_list, key=attrgetter('weight', 'inherit', 'is_empty', 'star', 'pound', 'under', 'option', 'wordcount', 'len', 'alphabet')) return [triggers[item.index] for item in sorted_list]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_list'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'block', 'children': ['6', '10', '26', '62', '66', '102']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'by_length'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': ['17']},{'id': '17', 'type': 'binary_operator', 'children': ['18', '22'], 'value': '-'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'word2'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'word1'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '29', 'type': 'block', 'children': ['30', '42', '53']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cword'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'word_count'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '41', 'type': 'True', 'children': []},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'not'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cword'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cword'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'cword'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '65', 'type': 'list', 'children': [], 'value': '[]'},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '79']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '70', 'type': 'argument_list', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '78', 'type': 'True', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '95']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '85', 'type': 'argument_list', 'children': ['86', '89', '92']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'track'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '94', 'type': 'True', 'children': []},{'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': 'output'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'output'}
def sort_list(items): track = {} def by_length(word1, word2): return len(word2) - len(word1) for item in items: cword = utils.word_count(item, all=True) if cword not in track: track[cword] = [] track[cword].append(item) output = [] for count in sorted(track.keys(), reverse=True): sort = sorted(track[count], key=len, reverse=True) output.extend(sort) return output
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_replies'},{'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': 'thats'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '25', '32', '111', '127', '148']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '16']},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '15', 'type': 'string', 'children': [], 'value': '"topics"'},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '24']},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '23', 'type': 'string', 'children': [], 'value': '"thats"'},{'id': '24', 'type': 'dictionary', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_say'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"Sorting triggers..."'},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '41']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_topics'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '51', '62', '81', '92']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_say'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'},{'id': '49', 'type': 'string', 'children': [], 'value': '"Analyzing topic "'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'alltrig'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'inherit_utils'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_topic_triggers'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '61', 'type': 'False', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '71']},{'id': '64', 'type': 'subscript', 'children': ['65', '70']},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '69', 'type': 'string', 'children': [], 'value': '"topics"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'sort_trigger_set'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'alltrig'},{'id': '77', 'type': 'True', 'children': []},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_say'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'that_triggers'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'inherit_utils'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_topic_triggers'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '91', 'type': 'True', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '101']},{'id': '94', 'type': 'subscript', 'children': ['95', '100']},{'id': '95', 'type': 'subscript', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '99', 'type': 'string', 'children': [], 'value': '"thats"'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sort_trigger_set'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'that_triggers'},{'id': '107', 'type': 'False', 'children': []},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_say'},{'id': '111', 'type': 'if_statement', 'children': ['112', '118']},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'},{'id': '114', 'type': 'string', 'children': [], 'value': '"lists"'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '126']},{'id': '121', 'type': 'subscript', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '125', 'type': 'string', 'children': [], 'value': '"lists"'},{'id': '126', 'type': 'dictionary', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '136']},{'id': '129', 'type': 'subscript', 'children': ['130', '135']},{'id': '130', 'type': 'subscript', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '134', 'type': 'string', 'children': [], 'value': '"lists"'},{'id': '135', 'type': 'string', 'children': [], 'value': '"sub"'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sort_list'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_sub'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '157']},{'id': '150', 'type': 'subscript', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '155', 'type': 'string', 'children': [], 'value': '"lists"'},{'id': '156', 'type': 'string', 'children': [], 'value': '"person"'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'sorting'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sort_list'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_person'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '168', 'type': 'argument_list', 'children': []}
def sort_replies(self, thats=False): self._sorted["topics"] = {} self._sorted["thats"] = {} self._say("Sorting triggers...") for topic in self._topics.keys(): self._say("Analyzing topic " + topic) alltrig = inherit_utils.get_topic_triggers(self, topic, False) self._sorted["topics"][topic] = sorting.sort_trigger_set(alltrig, True, self._say) that_triggers = inherit_utils.get_topic_triggers(self, topic, True) self._sorted["thats"][topic] = sorting.sort_trigger_set(that_triggers, False, self._say) if not "lists" in self._sorted: self._sorted["lists"] = {} self._sorted["lists"]["sub"] = sorting.sort_list(self._sub.keys()) self._sorted["lists"]["person"] = sorting.sort_list(self._person.keys())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'all'},{'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': 'page'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '10', 'type': 'integer', 'children': [], 'value': '10'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '13', 'type': 'string', 'children': [], 'value': '"latest"'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_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': '_all'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '25', '28']},{'id': '21', 'type': 'string', 'children': [], 'value': '"/photos"'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'order_by'}
def all(self, page=1, per_page=10, order_by="latest"): return self._all("/photos", page=page, per_page=per_page, order_by=order_by)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'photos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '11', 'type': 'integer', 'children': [], 'value': '10'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '14', 'type': 'string', 'children': [], 'value': '"latest"'},{'id': '15', 'type': 'block', 'children': ['16', '27', '46']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': '"/users/{username}/photos"'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_photos'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '40', '43']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'per_page'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'PhotoModel'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'parse_list'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'result'}
def photos(self, username, page=1, per_page=10, order_by="latest"): url = "/users/{username}/photos".format(username=username) result = self._photos(url, username, page=page, per_page=per_page, order_by=order_by) return PhotoModel.parse_list(result)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'callable'},{'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': 'nans'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '23', '123']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'jitfunc'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'nb'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'njit'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'nogil'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'function_definition', 'children': ['24', '25', '30']},{'id': '24', 'type': 'function_name', 'children': [], 'value': '_loop'},{'id': '25', 'type': 'parameters', 'children': ['26', '27', '28', '29']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sortidx'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'group_idx'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '30', 'type': 'block', 'children': ['31', '38', '44', '50', '57']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'group_idx_srt'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'group_idx'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sortidx'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'a_srt'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sortidx'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'step_indices'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'group_idx_srt'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '68']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '67'], 'value': '-'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'block', 'children': ['69', '83', '89', '99', '109']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'stop_idx'},{'id': '74', 'type': 'expression_list', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '+'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ri'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'group_idx_srt'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '<'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ri'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'raise_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': '"negative indices not supported"'},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '>='},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ri'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'raise_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': '"one or more indices in group_idx are too large"'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ri'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'jitfunc'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'a_srt'},{'id': '119', 'type': 'slice', 'children': ['120', '121', '122']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '121', 'type': 'colon', 'children': []},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'stop_idx'},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'nb'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'njit'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_loop'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'nogil'},{'id': '132', 'type': 'True', 'children': []}
def callable(self, nans=False): jitfunc = nb.njit(self.func, nogil=True) def _loop(sortidx, group_idx, a, ret): size = len(ret) group_idx_srt = group_idx[sortidx] a_srt = a[sortidx] indices = step_indices(group_idx_srt) for i in range(len(indices) - 1): start_idx, stop_idx = indices[i], indices[i + 1] ri = group_idx_srt[start_idx] if ri < 0: raise ValueError("negative indices not supported") if ri >= size: raise ValueError("one or more indices in group_idx are too large") ret[ri] = jitfunc(a_srt[start_idx:stop_idx]) return nb.njit(_loop, nogil=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'scores2recos'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '33']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '20', 'type': 'if_statement', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'rev'},{'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': 'sorted_indices'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '28', 'type': 'slice', 'children': ['29', '30', '31']},{'id': '29', 'type': 'colon', 'children': []},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'expression_list', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'scores'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'}
def scores2recos(self, scores, candidates, rev=False): sorted_indices = np.argsort(scores) if rev: sorted_indices = sorted_indices[::-1] return candidates[sorted_indices], scores[sorted_indices]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16', '28']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'commutative_sequence_variable_partition_iter'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Multiset'},{'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'generic_type', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '13', 'type': 'type_parameter', 'children': ['14']},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'VariableWithCount'},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'generic_type', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Iterator'},{'id': '19', 'type': 'type_parameter', 'children': ['20']},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'generic_type', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '23', 'type': 'type_parameter', 'children': ['24', '26']},{'id': '24', 'type': 'type', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '26', 'type': 'type', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Multiset'},{'id': '28', 'type': 'block', 'children': ['29', '47', '51', '73', '89']},{'id': '29', 'type': 'if_statement', 'children': ['30', '36']},{'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': 'variables'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'block', 'children': ['37', '46']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'yield', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_commutative_single_variable_partiton_iter'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'return_statement', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'generators'},{'id': '50', 'type': 'list', 'children': [], 'value': '[]'},{'id': '51', 'type': 'for_statement', 'children': ['52', '55', '60']},{'id': '52', 'type': 'pattern_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'generators'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_make_variable_generator_factory'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '78', 'type': 'generator_expression', 'children': ['79', '86']},{'id': '79', 'type': 'tuple', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'Multiset'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '97']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'generator_chain'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '95', 'type': 'list_splat', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'generators'},{'id': '97', 'type': 'block', 'children': ['98', '102', '153']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '101', 'type': 'True', 'children': []},{'id': '102', 'type': 'for_statement', 'children': ['103', '104', '105']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'if_statement', 'children': ['107', '123', '134']},{'id': '107', 'type': 'boolean_operator', 'children': ['108', '113'], 'value': 'and'},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '112'], 'value': 'is'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '122'], 'value': '=='},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '131']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '134', 'type': 'elif_clause', 'children': ['135', '147']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '144'], 'value': '<'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'minimum'},{'id': '147', 'type': 'block', 'children': ['148', '152']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '151', 'type': 'False', 'children': []},{'id': '152', 'type': 'break_statement', 'children': []},{'id': '153', 'type': 'if_statement', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'valid'},{'id': '155', 'type': 'block', 'children': ['156', '165']},{'id': '156', 'type': 'if_statement', 'children': ['157', '160']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'in'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'delete_statement', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'subst'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'yield', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'subst'}
def commutative_sequence_variable_partition_iter(values: Multiset, variables: List[VariableWithCount] ) -> Iterator[Dict[str, Multiset]]: if len(variables) == 1: yield from _commutative_single_variable_partiton_iter(values, variables[0]) return generators = [] for value, count in values.items(): generators.append(_make_variable_generator_factory(value, count, variables)) initial = dict((var.name, Multiset()) for var in variables) for subst in generator_chain(initial, *generators): valid = True for var in variables: if var.default is not None and len(subst[var.name]) == 0: subst[var.name] = var.default elif len(subst[var.name]) < var.minimum: valid = False break if valid: if None in subst: del subst[None] yield subst
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iter_cookie_browse_sorting'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cookies'},{'id': '5', 'type': 'block', 'children': ['6', '8']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Get sorting-cookie from cookies dictionary.\n :yields: tuple of path and sorting property\n :ytype: 2-tuple of strings\n '''"},{'id': '8', 'type': 'try_statement', 'children': ['9', '51']},{'id': '9', 'type': 'block', 'children': ['10', '25']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '13', 'type': 'call', 'children': ['14', '23']},{'id': '14', 'type': 'attribute', 'children': ['15', '22']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cookies'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'browse-sorting'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'e30='"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'ascii'"},{'id': '25', 'type': 'for_statement', 'children': ['26', '29', '45']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '43']},{'id': '35', 'type': 'attribute', 'children': ['36', '42']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'base64'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'b64decode'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'yield', 'children': ['48']},{'id': '48', 'type': 'expression_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '51', 'type': 'except_clause', 'children': ['52', '59']},{'id': '52', 'type': 'as_pattern', 'children': ['53', '57']},{'id': '53', 'type': 'tuple', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '57', 'type': 'as_pattern_target', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'e'}
def iter_cookie_browse_sorting(cookies): ''' Get sorting-cookie from cookies dictionary. :yields: tuple of path and sorting property :ytype: 2-tuple of strings ''' try: data = cookies.get('browse-sorting', 'e30=').encode('ascii') for path, prop in json.loads(base64.b64decode(data).decode('utf-8')): yield path, prop except (ValueError, TypeError, KeyError) as e: logger.exception(e)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cookie_browse_sorting'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '6', 'type': 'block', 'children': ['7', '9', '30']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Get sorting-cookie data for path of current request.\n :returns: sorting property\n :rtype: string\n '''"},{'id': '9', 'type': 'if_statement', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '22']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'cpath'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'cprop'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'iter_cookie_browse_sorting'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cookies'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cpath'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cprop'},{'id': '30', 'type': 'return_statement', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'default'}
def get_cookie_browse_sorting(path, default): ''' Get sorting-cookie data for path of current request. :returns: sorting property :rtype: string ''' if request: for cpath, cprop in iter_cookie_browse_sorting(request.cookies): if path == cpath: return cprop return default
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'integral'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'requestContext'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '6', 'type': 'block', 'children': ['7', '11', '90']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '14', 'type': 'block', 'children': ['15', '19', '23', '52', '60', '77', '83']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'newValues'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '22', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '39']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'newValues'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41', '45']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '+='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'},{'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': 'newValues'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'newName'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'},{'id': '56', 'type': 'string', 'children': [], 'value': '"integral(%s)"'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'newSeries'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'TimeSeries'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67', '70', '73', '76']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'newName'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'newValues'},{'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': 'newSeries'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pathExpression'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'newName'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'newSeries'},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'results'}
def integral(requestContext, seriesList): results = [] for series in seriesList: newValues = [] current = 0.0 for val in series: if val is None: newValues.append(None) else: current += val newValues.append(current) newName = "integral(%s)" % series.name newSeries = TimeSeries(newName, series.start, series.end, series.step, newValues) newSeries.pathExpression = newName results.append(newSeries) return results
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_metabolite2kegg'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'metabolite'},{'id': '5', 'type': 'block', 'children': ['6', '16', '27', '43', '78', '88']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': '"Looking for KEGG compound identifier for %s."'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'metabolite'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'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': 'metabolite'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': '"kegg.compound"'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '42']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"No kegg.compound annotation for metabolite %s."'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'metabolite'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '42', 'type': 'return_statement', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '57', '60']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '50', '51'], 'value': 'and'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '50', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': '"C"'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '66']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'try_statement', 'children': ['68', '74']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_smallest_compound_id'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'kegg_annotation'},{'id': '74', 'type': 'except_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'return_statement', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': '"No matching kegg.compound annotation for metabolite %s."'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'metabolite'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '88', 'type': 'return_statement', 'children': []}
def map_metabolite2kegg(metabolite): logger.debug("Looking for KEGG compound identifier for %s.", metabolite.id) kegg_annotation = metabolite.annotation.get("kegg.compound") if kegg_annotation is None: logger.warning("No kegg.compound annotation for metabolite %s.", metabolite.id) return if isinstance(kegg_annotation, string_types) and \ kegg_annotation.startswith("C"): return kegg_annotation elif isinstance(kegg_annotation, Iterable): try: return get_smallest_compound_id(kegg_annotation) except ValueError: return logger.warning( "No matching kegg.compound annotation for metabolite %s.", metabolite.id ) return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'preProcessForComparison'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_size'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'size_tolerance_prct'},{'id': '7', 'type': 'block', 'children': ['8', '12', '53', '71', '75', '136', '148', '172', '377']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '21'], 'value': 'is'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'source_quality'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'CoverSourceQuality'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'REFERENCE'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '48']},{'id': '26', 'type': '()', 'children': ['27']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '32'], 'value': 'or'},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '47'], 'value': '>'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'CoverSourceResult'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'compare'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41', '44']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'target_size'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'target_size'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'size_tolerance_prct'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'size_tolerance_prct'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'filterfalse'},{'id': '63', 'type': 'argument_list', 'children': ['64', '70']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': '"is_only_reference"'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'no_dup_results'},{'id': '74', 'type': 'list', 'children': [], 'value': '[]'},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '78', 'type': 'block', 'children': ['79', '83', '125']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'is_dup'},{'id': '82', 'type': 'False', 'children': []},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'result_comp'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'if_statement', 'children': ['88', '119']},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '103'], 'value': 'and'},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '95'], 'value': 'and'},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'result_comp'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '=='},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'result_comp'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'urls'},{'id': '103', 'type': '()', 'children': ['104']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '118'], 'value': '<'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'compare'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111', '112', '115']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'result_comp'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'target_size'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'target_size'},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'size_tolerance_prct'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'size_tolerance_prct'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'block', 'children': ['120', '124']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'is_dup'},{'id': '123', 'type': 'True', 'children': []},{'id': '124', 'type': 'break_statement', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '128']},{'id': '126', 'type': 'not_operator', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'is_dup'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'no_dup_results'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'dup_count'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '144'], 'value': '-'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'no_dup_results'},{'id': '148', 'type': 'if_statement', 'children': ['149', '152']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '>'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dup_count'},{'id': '151', 'type': 'integer', 'children': [], 'value': '0'},{'id': '152', 'type': 'block', 'children': ['153', '168']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '163']},{'id': '155', 'type': 'attribute', 'children': ['156', '162']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'string', 'children': [], 'value': '"Cover"'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'},{'id': '165', 'type': 'string', 'children': [], 'value': '"Removed %u duplicate results"'},{'id': '166', 'type': '()', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'dup_count'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'no_dup_results'},{'id': '172', 'type': 'if_statement', 'children': ['173', '176', '363']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'is'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '175', 'type': 'None', 'children': []},{'id': '176', 'type': 'block', 'children': ['177', '192', '198', '202', '230', '264', '275', '285']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '187']},{'id': '179', 'type': 'attribute', 'children': ['180', '186']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': '"Cover"'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '%'},{'id': '189', 'type': 'string', 'children': [], 'value': '"Reference is: %s"'},{'id': '190', 'type': '()', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'is_similar_to_reference'},{'id': '197', 'type': 'True', 'children': []},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '201', 'type': 'list', 'children': [], 'value': '[]'},{'id': '202', 'type': 'for_statement', 'children': ['203', '204', '205']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '205', 'type': 'block', 'children': ['206', '214', '223']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'coroutine'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'updateSignature'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'coroutine'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '230', 'type': 'if_statement', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'is_only_reference'},{'id': '234', 'type': 'block', 'children': ['235', '240', '248', '257']},{'id': '235', 'type': 'assert_statement', 'children': ['236']},{'id': '236', 'type': '()', 'children': ['237']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'not'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'coroutine'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'updateSignature'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'ensure_future'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'coroutine'},{'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': 'futures'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '264', 'type': 'if_statement', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'await', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'asyncio'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '275', 'type': 'for_statement', 'children': ['276', '277', '278']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'futures'},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'future'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '284', 'type': 'argument_list', 'children': []},{'id': '285', 'type': 'for_statement', 'children': ['286', '287', '288']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'if_statement', 'children': ['290', '309']},{'id': '290', 'type': '()', 'children': ['291']},{'id': '291', 'type': 'boolean_operator', 'children': ['292', '303'], 'value': 'and'},{'id': '292', 'type': 'boolean_operator', 'children': ['293', '297'], 'value': 'and'},{'id': '293', 'type': '()', 'children': ['294']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': 'is'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '297', 'type': '()', 'children': ['298']},{'id': '298', 'type': 'comparison_operator', 'children': ['299', '302'], 'value': 'is'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'thumbnail_sig'},{'id': '302', 'type': 'None', 'children': []},{'id': '303', 'type': '()', 'children': ['304']},{'id': '304', 'type': 'comparison_operator', 'children': ['305', '308'], 'value': 'is'},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'thumbnail_sig'},{'id': '308', 'type': 'None', 'children': []},{'id': '309', 'type': 'block', 'children': ['310', '326']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'is_similar_to_reference'},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'areImageSigsSimilar'},{'id': '319', 'type': 'argument_list', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'thumbnail_sig'},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'thumbnail_sig'},{'id': '326', 'type': 'if_statement', 'children': ['327', '330', '346']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'is_similar_to_reference'},{'id': '330', 'type': 'block', 'children': ['331']},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '341']},{'id': '333', 'type': 'attribute', 'children': ['334', '340']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'string', 'children': [], 'value': '"Cover"'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'},{'id': '343', 'type': 'string', 'children': [], 'value': '"%s is similar to reference"'},{'id': '344', 'type': '()', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '346', 'type': 'else_clause', 'children': ['347']},{'id': '347', 'type': 'block', 'children': ['348']},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '358']},{'id': '350', 'type': 'attribute', 'children': ['351', '357']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'string', 'children': [], 'value': '"Cover"'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'binary_operator', 'children': ['360', '361'], 'value': '%'},{'id': '360', 'type': 'string', 'children': [], 'value': '"%s is NOT similar to reference"'},{'id': '361', 'type': '()', 'children': ['362']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '363', 'type': 'else_clause', 'children': ['364']},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'call', 'children': ['367', '375']},{'id': '367', 'type': 'attribute', 'children': ['368', '374']},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'string', 'children': [], 'value': '"Cover"'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '375', 'type': 'argument_list', 'children': ['376']},{'id': '376', 'type': 'string', 'children': [], 'value': '"No reference result found"'},{'id': '377', 'type': 'return_statement', 'children': ['378']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'results'}
async def preProcessForComparison(results, target_size, size_tolerance_prct): reference = None for result in results: if result.source_quality is CoverSourceQuality.REFERENCE: if ((reference is None) or (CoverSourceResult.compare(result, reference, target_size=target_size, size_tolerance_prct=size_tolerance_prct) > 0)): reference = result results = list(itertools.filterfalse(operator.attrgetter("is_only_reference"), results)) no_dup_results = [] for result in results: is_dup = False for result_comp in results: if ((result_comp is not result) and (result_comp.urls == result.urls) and (__class__.compare(result, result_comp, target_size=target_size, size_tolerance_prct=size_tolerance_prct) < 0)): is_dup = True break if not is_dup: no_dup_results.append(result) dup_count = len(results) - len(no_dup_results) if dup_count > 0: logging.getLogger("Cover").info("Removed %u duplicate results" % (dup_count)) results = no_dup_results if reference is not None: logging.getLogger("Cover").info("Reference is: %s" % (reference)) reference.is_similar_to_reference = True futures = [] for result in results: coroutine = result.updateSignature() future = asyncio.ensure_future(coroutine) futures.append(future) if reference.is_only_reference: assert(reference not in results) coroutine = reference.updateSignature() future = asyncio.ensure_future(coroutine) futures.append(future) if futures: await asyncio.wait(futures) for future in futures: future.result() for result in results: if ((result is not reference) and (result.thumbnail_sig is not None) and (reference.thumbnail_sig is not None)): result.is_similar_to_reference = __class__.areImageSigsSimilar(result.thumbnail_sig, reference.thumbnail_sig) if result.is_similar_to_reference: logging.getLogger("Cover").debug("%s is similar to reference" % (result)) else: logging.getLogger("Cover").debug("%s is NOT similar to reference" % (result)) else: logging.getLogger("Cover").warning("No reference result found") return results
{'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': 'order'},{'id': '7', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '8', 'type': 'block', 'children': ['9', '15', '56']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '__prepare'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '23']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28', '40']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '27', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '55', 'type': 'True', 'children': []},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, order="asc"): self.__prepare() if isinstance(self._json_data, list): if order == "asc": self._json_data = sorted(self._json_data) else: self._json_data = sorted(self._json_data, reverse=True) return self
{'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': 'property'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '9', 'type': 'block', 'children': ['10', '16', '79']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'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': '__prepare'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '29', '52']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '28', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'lambda', 'children': ['44', '46']},{'id': '44', 'type': 'lambda_parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '52', 'type': 'else_clause', 'children': ['53']},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '61', 'type': 'argument_list', 'children': ['62', '65', '76']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': '_json_data'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'lambda', 'children': ['68', '70']},{'id': '68', 'type': 'lambda_parameters', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'property'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '78', 'type': 'True', 'children': []},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort_by(self, property, order="asc"): self.__prepare() if isinstance(self._json_data, list): if order == "asc": self._json_data = sorted( self._json_data, key=lambda x: x.get(property) ) else: self._json_data = sorted( self._json_data, key=lambda x: x.get(property), reverse=True ) return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'seps'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'PATH_SEPS'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'idx_reg'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_JSNP_GET_ARRAY_IDX_REG'},{'id': '12', 'type': 'block', 'children': ['13', '28', '36']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '21']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_jsnp_unescape'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': '_split_path'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'seps'},{'id': '28', 'type': 'if_statement', 'children': ['29', '31']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'tuple', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'try_statement', 'children': ['37', '115']},{'id': '37', 'type': 'block', 'children': ['38', '54', '72', '93']},{'id': '38', 'type': 'if_statement', 'children': ['39', '45']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'tuple', 'children': ['48', '53']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'string', 'children': [], 'value': "''"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'prnt'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '61', 'type': 'argument_list', 'children': ['62', '65', '71']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'getitem'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '67', 'type': 'slice', 'children': ['68', '69']},{'id': '68', 'type': 'colon', 'children': []},{'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '84'], 'value': 'and'},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'is_list_like'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'prnt'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'idx_reg'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'conditional_expression', 'children': ['95', '106', '107'], 'value': 'if'},{'id': '95', 'type': 'tuple', 'children': ['96', '105']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'prnt'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '103', 'type': 'unary_operator', 'children': ['104'], 'value': '-'},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'string', 'children': [], 'value': "''"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '107', 'type': 'tuple', 'children': ['108', '114']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'prnt'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '112', 'type': 'unary_operator', 'children': ['113'], 'value': '-'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'string', 'children': [], 'value': "''"},{'id': '115', 'type': 'except_clause', 'children': ['116', '123']},{'id': '116', 'type': 'as_pattern', 'children': ['117', '121']},{'id': '117', 'type': 'tuple', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '121', 'type': 'as_pattern_target', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'tuple', 'children': ['126', '127']},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'exc'}
def get(dic, path, seps=PATH_SEPS, idx_reg=_JSNP_GET_ARRAY_IDX_REG): items = [_jsnp_unescape(p) for p in _split_path(path, seps)] if not items: return (dic, '') try: if len(items) == 1: return (dic[items[0]], '') prnt = functools.reduce(operator.getitem, items[:-1], dic) arr = anyconfig.utils.is_list_like(prnt) and idx_reg.match(items[-1]) return (prnt[int(items[-1])], '') if arr else (prnt[items[-1]], '') except (TypeError, KeyError, IndexError) as exc: return (None, str(exc))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupby'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'itr'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key_fn'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'return_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '14', 'type': 'argument_list', 'children': ['15', '22']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'itr'},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key_fn'},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key_fn'}
def groupby(itr, key_fn=None): return itertools.groupby(sorted(itr, key=key_fn), key=key_fn)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'open'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '13', 'type': 'block', 'children': ['14', '24', '45']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'forced_type'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '24', 'type': 'if_statement', 'children': ['25', '35']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'wopen'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'dictionary_splat', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ropen'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'dictionary_splat', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'options'}
def open(path, mode=None, ac_parser=None, **options): psr = find(path, forced_type=ac_parser) if mode is not None and mode.startswith('w'): return psr.wopen(path, **options) return psr.ropen(path, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'single_load'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '16', 'type': 'block', 'children': ['17', '19', '37', '51', '61']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_single_load'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26', '29', '32', '35']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'input_'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '35', 'type': 'dictionary_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_maybe_schema'},{'id': '42', 'type': 'argument_list', 'children': ['43', '46', '49']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '49', 'type': 'dictionary_splat', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_try_validate'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '59', 'type': 'dictionary_splat', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '70', 'type': 'dictionary_splat', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'options'}
def single_load(input_, ac_parser=None, ac_template=False, ac_context=None, **options): r cnf = _single_load(input_, ac_parser=ac_parser, ac_template=ac_template, ac_context=ac_context, **options) schema = _maybe_schema(ac_template=ac_template, ac_context=ac_context, **options) cnf = _try_validate(cnf, schema, **options) return anyconfig.query.query(cnf, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'multi_load'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '16', 'type': 'block', 'children': ['17', '19', '35', '49', '55', '69', '91', '95', '147', '163', '173']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"ac_marker"'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': '"marker"'},{'id': '34', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_maybe_schema'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44', '47']},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '47', 'type': 'dictionary_splat', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '53', 'type': 'string', 'children': [], 'value': '"ac_schema"'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'expand_paths'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '69', 'type': 'if_statement', 'children': ['70', '78']},{'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': 'anyconfig'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'are_same_file_types'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'forced_type'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '95', 'type': 'for_statement', 'children': ['96', '97', '98']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '98', 'type': 'block', 'children': ['99', '107', '125']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cups'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_single_load'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114', '117', '120', '123']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '123', 'type': 'dictionary_splat', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '125', 'type': 'if_statement', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'cups'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '132', '137']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '131', 'type': 'None', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'cups'},{'id': '137', 'type': 'else_clause', 'children': ['138']},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'cups'},{'id': '145', 'type': 'dictionary_splat', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '147', 'type': 'if_statement', 'children': ['148', '151']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '159']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'convert_to'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'dictionary', 'children': []},{'id': '161', 'type': 'dictionary_splat', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_try_validate'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '171', 'type': 'dictionary_splat', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'cnf'},{'id': '182', 'type': 'dictionary_splat', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'options'}
def multi_load(inputs, ac_parser=None, ac_template=False, ac_context=None, **options): r marker = options.setdefault("ac_marker", options.get("marker", '*')) schema = _maybe_schema(ac_template=ac_template, ac_context=ac_context, **options) options["ac_schema"] = None paths = anyconfig.utils.expand_paths(inputs, marker=marker) if anyconfig.utils.are_same_file_types(paths): ac_parser = find(paths[0], forced_type=ac_parser) cnf = ac_context for path in paths: opts = options.copy() cups = _single_load(path, ac_parser=ac_parser, ac_template=ac_template, ac_context=cnf, **opts) if cups: if cnf is None: cnf = cups else: merge(cnf, cups, **options) if cnf is None: return anyconfig.dicts.convert_to({}, **options) cnf = _try_validate(cnf, schema, **options) return anyconfig.query.query(cnf, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'ac_dict'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '19', 'type': 'block', 'children': ['20', '22', '38', '68', '87']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"ac_marker"'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '"marker"'},{'id': '37', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '38', 'type': 'if_statement', 'children': ['39', '48']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'is_path_like_object'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'single_load'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '57', '60', '63', '66']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ac_dict'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ac_dict'},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '66', 'type': 'dictionary_splat', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '68', 'type': 'if_statement', 'children': ['69', '79']},{'id': '69', 'type': 'not_operator', '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': 'anyconfig'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'is_paths'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'string', 'children': [], 'value': '"Possible invalid input %r"'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'multi_load'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '95', '98', '101', '104']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'path_specs'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ac_dict'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'ac_dict'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ac_template'},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ac_context'},{'id': '104', 'type': 'dictionary_splat', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'options'}
def load(path_specs, ac_parser=None, ac_dict=None, ac_template=False, ac_context=None, **options): r marker = options.setdefault("ac_marker", options.get("marker", '*')) if anyconfig.utils.is_path_like_object(path_specs, marker): return single_load(path_specs, ac_parser=ac_parser, ac_dict=ac_dict, ac_template=ac_template, ac_context=ac_context, **options) if not anyconfig.utils.is_paths(path_specs, marker): raise ValueError("Possible invalid input %r" % path_specs) return multi_load(path_specs, ac_parser=ac_parser, ac_dict=ac_dict, ac_template=ac_template, ac_context=ac_context, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '11', 'type': 'block', 'children': ['12', '23', '33', '43']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ioi'},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'anyconfig'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ioinfo'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'make'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ioi'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'forced_type'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'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': 'LOGGER'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': '"Dumping: %s"'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ioi'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ioi'},{'id': '51', 'type': 'dictionary_splat', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'options'}
def dump(data, out, ac_parser=None, **options): ioi = anyconfig.ioinfo.make(out) psr = find(ioi, forced_type=ac_parser) LOGGER.info("Dumping: %s", ioi.path) psr.dump(data, ioi, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dumps'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '10', 'type': 'block', 'children': ['11', '21']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'forced_type'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ac_parser'},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'psr'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '28', 'type': 'dictionary_splat', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'options'}
def dumps(data, ac_parser=None, **options): psr = find(None, forced_type=ac_parser) return psr.dumps(data, **options)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_response'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '9', 'type': 'type_parameter', 'children': ['10', '12']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '16', 'type': 'block', 'children': ['17', '25', '32', '59', '95']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'root_order'},{'id': '20', 'type': 'list', 'children': ['21', '22', '23', '24'], 'value': '["jsonrpc", "result", "error", "id"]'},{'id': '21', 'type': 'string', 'children': [], 'value': '"jsonrpc"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"result"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"error"'},{'id': '24', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'error_order'},{'id': '28', 'type': 'list', 'children': ['29', '30', '31'], 'value': '["code", "message", "data"]'},{'id': '29', 'type': 'string', 'children': [], 'value': '"code"'},{'id': '30', 'type': 'string', 'children': [], 'value': '"message"'},{'id': '31', 'type': 'string', 'children': [], 'value': '"data"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '40', 'type': 'argument_list', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'lambda', 'children': ['49', '51']},{'id': '49', 'type': 'lambda_parameters', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'root_order'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'},{'id': '61', 'type': 'string', 'children': [], 'value': '"error"'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'req'},{'id': '68', 'type': 'string', 'children': [], 'value': '"error"'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '74', 'type': 'argument_list', 'children': ['75', '82']},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '79', 'type': 'string', 'children': [], 'value': '"error"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '84', 'type': 'lambda', 'children': ['85', '87']},{'id': '85', 'type': 'lambda_parameters', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'error_order'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'req'}
def sort_response(response: Dict[str, Any]) -> OrderedDict: root_order = ["jsonrpc", "result", "error", "id"] error_order = ["code", "message", "data"] req = OrderedDict(sorted(response.items(), key=lambda k: root_order.index(k[0]))) if "error" in response: req["error"] = OrderedDict( sorted(response["error"].items(), key=lambda k: error_order.index(k[0])) ) return req
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_request'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Dict'},{'id': '9', 'type': 'type_parameter', 'children': ['10', '12']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '16', 'type': 'block', 'children': ['17', '25']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '20', 'type': 'list', 'children': ['21', '22', '23', '24'], 'value': '["jsonrpc", "method", "params", "id"]'},{'id': '21', 'type': 'string', 'children': [], 'value': '"jsonrpc"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"method"'},{'id': '23', 'type': 'string', 'children': [], 'value': '"params"'},{'id': '24', 'type': 'string', 'children': [], 'value': '"id"'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'lambda', 'children': ['40', '42']},{'id': '40', 'type': 'lambda_parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'}
def sort_request(request: Dict[str, Any]) -> OrderedDict: sort_order = ["jsonrpc", "method", "params", "id"] return OrderedDict(sorted(request.items(), key=lambda k: sort_order.index(k[0])))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'container_count'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'no_float32'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '33', '39']},{'id': '19', 'type': 'if_statement', 'children': ['20', '27']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': "'fp.write not callable'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'fp_write'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '__encode_value'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45', '46', '47', '48', '49']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'fp_write'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '45', 'type': 'dictionary', 'children': []},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'container_count'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'no_float32'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'default'}
def dump(obj, fp, container_count=False, sort_keys=False, no_float32=True, default=None): if not callable(fp.write): raise TypeError('fp.write not callable') fp_write = fp.write __encode_value(fp_write, obj, {}, container_count, sort_keys, no_float32, default)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'torrents'},{'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': 'filters'},{'id': '7', 'type': 'block', 'children': ['8', '12', '37']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '21']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '31']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'conditional_expression', 'children': ['26', '27', '30'], 'value': 'if'},{'id': '26', 'type': 'string', 'children': [], 'value': "'filter'"},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '=='},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '29', 'type': 'string', 'children': [], 'value': "'status'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'query/torrents'"},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'}
def torrents(self, **filters): params = {} for name, value in filters.items(): name = 'filter' if name == 'status' else name params[name] = value return self._get('query/torrents', params=params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_global_color_table'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '5', 'type': 'block', 'children': ['6', '24', '43', '55', '69']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'global_color_table'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'string', 'children': [], 'value': "b''"},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '13', 'type': 'generator_expression', 'children': ['14', '17']},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'full_table_size'},{'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '**'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': '()', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '+'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '34', 'type': 'argument_list', 'children': ['35', '42']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_color_table_size'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '42', 'type': 'integer', 'children': [], 'value': '2'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'repeats'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '*'},{'id': '47', 'type': 'integer', 'children': [], 'value': '3'},{'id': '48', 'type': '()', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '-'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'full_table_size'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'colors'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'struct'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'<{}x'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'repeats'},{'id': '69', 'type': 'return_statement', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'global_color_table'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'zeros'}
def _get_global_color_table(colors): global_color_table = b''.join(c[0] for c in colors.most_common()) full_table_size = 2**(1+int(get_color_table_size(len(colors)), 2)) repeats = 3 * (full_table_size - len(colors)) zeros = struct.pack('<{}x'.format(repeats)) return global_color_table + zeros
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'good_sequences_to_track'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'motion_threshold'},{'id': '7', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '8', 'type': 'block', 'children': ['9', '13', '17', '64', '95', '135', '166', '170', '174', '295']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'in_low'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'for_statement', 'children': ['18', '21', '25']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '46']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'motion_threshold'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'if_statement', 'children': ['32', '34']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_low'},{'id': '34', 'type': 'block', 'children': ['35', '42']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'in_low'},{'id': '45', 'type': 'True', 'children': []},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48', '60']},{'id': '48', 'type': 'if_statement', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'in_low'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'in_low'},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'function_definition', 'children': ['65', '66', '68']},{'id': '65', 'type': 'function_name', 'children': [], 'value': 'mean_score_func'},{'id': '66', 'type': 'parameters', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '68', 'type': 'block', 'children': ['69', '73', '77', '86']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '72', 'type': 'integer', 'children': [], 'value': '15'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '76', 'type': 'integer', 'children': [], 'value': '8'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '86', 'type': 'return_statement', 'children': ['87']},{'id': '87', 'type': 'binary_operator', 'children': ['88', '94'], 'value': '/'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '95', 'type': 'function_definition', 'children': ['96', '97', '99']},{'id': '96', 'type': 'function_name', 'children': [], 'value': 'max_score_func'},{'id': '97', 'type': 'parameters', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '99', 'type': 'block', 'children': ['100', '104', '108']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '103', 'type': 'integer', 'children': [], 'value': '40'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '107', 'type': 'integer', 'children': [], 'value': '8'},{'id': '108', 'type': 'if_statement', 'children': ['109', '112', '115']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '<='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'return_statement', 'children': ['114']},{'id': '114', 'type': 'float', 'children': [], 'value': '1.'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117', '126']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '134'], 'value': '/'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '135', 'type': 'function_definition', 'children': ['136', '137', '139']},{'id': '136', 'type': 'function_name', 'children': [], 'value': 'length_score_func'},{'id': '137', 'type': 'parameters', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '139', 'type': 'block', 'children': ['140', '144', '148', '157']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '143', 'type': 'integer', 'children': [], 'value': '30'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '147', 'type': 'integer', 'children': [], 'value': '10'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '157', 'type': 'return_statement', 'children': ['158']},{'id': '158', 'type': 'binary_operator', 'children': ['159', '165'], 'value': '/'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'normpdf'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163', '164']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'mu'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'top_val'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'min_length'},{'id': '169', 'type': 'integer', 'children': [], 'value': '5'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'sequences'},{'id': '173', 'type': 'list', 'children': [], 'value': '[]'},{'id': '174', 'type': 'for_statement', 'children': ['175', '178', '187']},{'id': '175', 'type': 'pattern_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '183', 'type': 'slice', 'children': ['184', '185']},{'id': '184', 'type': 'colon', 'children': []},{'id': '185', 'type': 'unary_operator', 'children': ['186'], 'value': '-'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'for_statement', 'children': ['189', '190', '197']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '192', 'type': 'slice', 'children': ['193', '196']},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'colon', 'children': []},{'id': '197', 'type': 'block', 'children': ['198', '204', '210', '221', '233', '245', '252', '266', '277', '285']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '-'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '204', 'type': 'if_statement', 'children': ['205', '208']},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': '<'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'min_length'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'continue_statement', 'children': []},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '215', 'type': 'slice', 'children': ['216', '217', '218']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'colon', 'children': []},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'm_score'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'mean_score_func'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'mx_score'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'max_score_func'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'l_score'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'length_score_func'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '%'},{'id': '259', 'type': 'string', 'children': [], 'value': '"%d, %d scores: (mean=%.5f, max=%.5f, length=%.5f)"'},{'id': '260', 'type': 'tuple', 'children': ['261', '262', '263', '264', '265']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'm_score'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'mx_score'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'l_score'},{'id': '266', 'type': 'if_statement', 'children': ['267', '275']},{'id': '267', 'type': 'comparison_operator', 'children': ['268', '274'], 'value': '<'},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272', '273']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'm_score'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'mx_score'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'l_score'},{'id': '274', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '275', 'type': 'block', 'children': ['276']},{'id': '276', 'type': 'continue_statement', 'children': []},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '280', 'type': 'binary_operator', 'children': ['281', '284'], 'value': '+'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '+'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'm_score'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'mx_score'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'l_score'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'sequences'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'tuple', 'children': ['292', '293', '294']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '295', 'type': 'return_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '308']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'sequences'},{'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '302', 'type': 'lambda', 'children': ['303', '305']},{'id': '303', 'type': 'lambda_parameters', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '307', 'type': 'integer', 'children': [], 'value': '2'},{'id': '308', 'type': 'keyword_argument', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '310', 'type': 'True', 'children': []}
def good_sequences_to_track(flow, motion_threshold=1.0): endpoints = [] in_low = False for i, val in enumerate(flow): if val < motion_threshold: if not in_low: endpoints.append(i) in_low = True else: if in_low: endpoints.append(i-1) in_low = False def mean_score_func(m): mu = 15 sigma = 8 top_val = normpdf(mu, mu, sigma) return normpdf(m, mu, sigma) / top_val def max_score_func(m): mu = 40 sigma = 8 if m <= mu: return 1. else: top_val = normpdf(mu, mu, sigma) return normpdf(m, mu, sigma) / top_val def length_score_func(l): mu = 30 sigma = 10 top_val = normpdf(mu, mu, sigma) return normpdf(l, mu, sigma) / top_val min_length = 5 sequences = [] for k, i in enumerate(endpoints[:-1]): for j in endpoints[k+1:]: length = j - i if length < min_length: continue seq = flow[i:j+1] m_score = mean_score_func(np.mean(seq)) mx_score = max_score_func(np.max(seq)) l_score = length_score_func(length) logger.debug("%d, %d scores: (mean=%.5f, max=%.5f, length=%.5f)" % (i,j,m_score, mx_score, l_score)) if min(m_score, mx_score, l_score) < 0.2: continue score = m_score + mx_score + l_score sequences.append((i, j, score)) return sorted(sequences, key=lambda x: x[2], reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_comparator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '6', 'type': 'block', 'children': ['7', '14', '24', '57', '71', '153']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reverses'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '20'], 'value': '*'},{'id': '18', 'type': 'list', 'children': ['19'], 'value': '[1]'},{'id': '19', 'type': 'integer', 'children': [], 'value': '1'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '24', 'type': 'for_statement', 'children': ['25', '28', '32']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '39']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '=='},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '39', 'type': 'block', 'children': ['40', '47']},{'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': 'reverses'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'unary_operator', 'children': ['46'], 'value': '-'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '52']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '54', 'type': 'slice', 'children': ['55', '56']},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '60', 'type': 'list_comprehension', 'children': ['61', '68']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'LOOKUP_SEP'},{'id': '67', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '71', 'type': 'function_definition', 'children': ['72', '73', '76']},{'id': '72', 'type': 'function_name', 'children': [], 'value': 'comparator'},{'id': '73', 'type': 'parameters', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '76', 'type': 'block', 'children': ['77', '88', '99', '119', '137']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'v1'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'list_splat', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'list_splat', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '99', 'type': 'if_statement', 'children': ['100', '106']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '105'], 'value': '=='},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'field_names'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '116'], 'value': '*'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_cmp'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'v1'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'reverses'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'multiply_iterables'},{'id': '124', 'type': 'argument_list', 'children': ['125', '136']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '130', 'type': 'argument_list', 'children': ['131', '134', '135']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_cmp'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'v1'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'v2'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'reverses'},{'id': '137', 'type': 'try_statement', 'children': ['138', '148']},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'return_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'dropwhile'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '__not__'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '148', 'type': 'except_clause', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'return_statement', 'children': ['152']},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'comparator'}
def _generate_comparator(cls, field_names): field_names = list(field_names) reverses = [1] * len(field_names) for i, field_name in enumerate(field_names): if field_name[0] == '-': reverses[i] = -1 field_names[i] = field_name[1:] field_names = [f.replace(LOOKUP_SEP, '.') for f in field_names] def comparator(i1, i2): v1 = attrgetter(*field_names)(i1) v2 = attrgetter(*field_names)(i2) if len(field_names) == 1: return cls._cmp(v1, v2) * reverses[0] order = multiply_iterables(list(map(cls._cmp, v1, v2)), reverses) try: return next(dropwhile(__not__, order)) except StopIteration: return 0 return comparator
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_segment_points'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '6', 'type': 'block', 'children': ['7', '11', '15', '24', '148', '168']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'mid'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '35']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'binary_operator', 'children': ['30', '34'], 'value': '-'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'block', 'children': ['36', '50', '137']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'distance_tt_point'},{'id': '41', 'type': 'argument_list', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '60']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '60', 'type': 'block', 'children': ['61', '73']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'distm'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'distance_tt_point'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '73', 'type': 'if_statement', 'children': ['74', '77']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '>'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dist'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'distm'},{'id': '77', 'type': 'block', 'children': ['78', '116']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '83', 'type': 'argument_list', 'children': ['84', '106']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '89', 'type': 'argument_list', 'children': ['90', '97']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'gen2arr'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'call', 'children': ['98', '105']},{'id': '98', 'type': 'attribute', 'children': ['99', '104']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'gen2arr'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'gen2arr'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '120']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '>'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'block', 'children': ['121', '127', '136']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '136', 'type': 'break_statement', 'children': []},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'Aps'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '+'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '158']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'mid'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'Bps'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '168', 'type': 'return_statement', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'mid'}
def sort_segment_points(Aps, Bps): mid = [] j = 0 mid.append(Aps[0]) for i in range(len(Aps)-1): dist = distance_tt_point(Aps[i], Aps[i+1]) for m in range(j, len(Bps)): distm = distance_tt_point(Aps[i], Bps[m]) if dist > distm: direction = dot(normalize(line(Aps[i].gen2arr(), Aps[i+1].gen2arr())), normalize(Bps[m].gen2arr())) if direction > 0: j = m + 1 mid.append(Bps[m]) break mid.append(Aps[i+1]) for m in range(j, len(Bps)): mid.append(Bps[m]) return mid
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'works'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '40', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '41', 'type': 'dictionary_splat_pattern', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '43', 'type': 'block', 'children': ['44', '46']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': '\'\'\'\n Search Crossref works\n :param ids: [Array] DOIs (digital object identifier) or other identifiers\n :param query: [String] A query string\n :param filter: [Hash] Filter options. See examples for usage.\n Accepts a dict, with filter names and their values. For repeating filter names\n pass in a list of the values to that filter name, e.g.,\n `{\'award_funder\': [\'10.13039/100004440\', \'10.13039/100000861\']}`.\n See https://github.com/CrossRef/rest-api-doc\n for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`\n and :func:`~habanero.Crossref.filter_details`\n :param offset: [Fixnum] Number of record to start at, from 1 to 10000\n :param limit: [Fixnum] Number of results to return. Not relavant when searching with specific dois.\n Default: 20. Max: 1000\n :param sample: [Fixnum] Number of random results to return. when you use the sample parameter,\n the limit and offset parameters are ignored. Max: 100\n :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort\n order will be by the relevance score. If no query is included, then the sort order\n will be by DOI update date. See sorting_ for possible values.\n :param order: [String] Sort order, one of \'asc\' or \'desc\'\n :param facet: [Boolean/String] Set to `true` to include facet results (default: false).\n Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`.\n See Facets_ for options.\n :param select: [String/list(Strings)] Crossref metadata records can be\n quite large. Sometimes you just want a few elements from the schema. You can "select"\n a subset of elements to return. This can make your API calls much more efficient. Not\n clear yet which fields are allowed here.\n :param cursor: [String] Cursor character string to do deep paging. Default is None.\n Pass in \'*\' to start deep paging. Any combination of query, filters and facets may be\n used with deep paging cursors. While rows may be specified along with cursor, offset\n and sample cannot be used.\n See https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md\n :param cursor_max: [Fixnum] Max records to retrieve. Only used when cursor param used. Because\n deep paging can result in continuous requests until all are retrieved, use this\n parameter to set a maximum number of records. Of course, if there are less records\n found than this value, you will get only those found.\n :param kwargs: additional named arguments passed on to `requests.get`, e.g., field\n queries (see examples and FieldQueries_) \n :return: A dict\n Usage::\n from habanero import Crossref\n cr = Crossref()\n cr.works()\n cr.works(ids = \'10.1371/journal.pone.0033693\')\n dois = [\'10.1371/journal.pone.0033693\', ]\n cr.works(ids = dois)\n x = cr.works(query = "ecology")\n x[\'status\']\n x[\'message-type\']\n x[\'message-version\']\n x[\'message\']\n x[\'message\'][\'total-results\']\n x[\'message\'][\'items-per-page\']\n x[\'message\'][\'query\']\n x[\'message\'][\'items\']\n x = cr.works(filter = {\'has_full_text\': True})\n x\n x = cr.works(filter = {\'has_full_text\': True})\n [ z[\'DOI\'] for z in x[\'message\'][\'items\'] ]\n [ {"doi": z[\'DOI\'], "url": z[\'URL\']} for z in x[\'message\'][\'items\'] ]\n for i in x[\'message\'][\'items\']:\n print i[\'DOI\']\n cr.works(filter = {\'has_full_text\': True})\n cr.works(filter = {\'has_funder\': True, \'has_full_text\': True})\n cr.works(filter = {\'award_number\': \'CBET-0756451\', \'award_funder\': \'10.13039/100000001\'})\n x = cr.works(filter = {\'award_funder\': [\'10.13039/100004440\', \'10.13039/100000861\']}, limit = 100)\n map(lambda z:z[\'funder\'][0][\'DOI\'], x[\'message\'][\'items\'])\n cr.works(query = "widget", cursor = "*", cursor_max = 100)\n res = cr.works(query = "octopus", cursor = "*", limit = 500)\n sum([ len(z[\'message\'][\'items\']) for z in res ])\n res = cr.works(query = "extravagant", cursor = "*", limit = 50, cursor_max = 500)\n sum([ len(z[\'message\'][\'items\']) for z in res ])\n res = cr.works(query = "widget", cursor = "*", cursor_max = 100)\n sum([ len(z[\'message\'][\'items\']) for z in res ])\n res = cr.works(query = "ecology", cursor = "*", cursor_max = 10000, limit = 1000)\n sum([ len(z[\'message\'][\'items\']) for z in res ])\n items = [ z[\'message\'][\'items\'] for z in res ]\n items = [ item for sublist in items for item in sublist ]\n [ z[\'DOI\'] for z in items ][0:50]\n res = cr.works(query = "ecology", query_author = \'carl boettiger\')\n [ x[\'author\'][0][\'family\'] for x in res[\'message\'][\'items\'] ]\n cr.works(query = "ecology", select = "DOI,title")\n cr.works(query = "ecology", select = ["DOI","title"])\n \'\'\''},{'id': '46', 'type': 'if_statement', 'children': ['47', '54', '82']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': '!='},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '53', 'type': 'string', 'children': [], 'value': "'NoneType'"},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '58', 'type': 'argument_list', 'children': ['59', '62', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'mailto'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '65', 'type': 'string', 'children': [], 'value': '"/works/"'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'dictionary_splat', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '112']},{'id': '86', 'type': 'attribute', 'children': ['87', '111']},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Request'},{'id': '89', 'type': 'argument_list', 'children': ['90', '93', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'mailto'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '96', 'type': 'string', 'children': [], 'value': '"/works/"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '108', 'type': 'None', 'children': []},{'id': '109', 'type': 'dictionary_splat', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'do_request'},{'id': '112', 'type': 'argument_list', 'children': []}
def works(self, ids = None, query = None, filter = None, offset = None, limit = None, sample = None, sort = None, order = None, facet = None, select = None, cursor = None, cursor_max = 5000, **kwargs): ''' Search Crossref works :param ids: [Array] DOIs (digital object identifier) or other identifiers :param query: [String] A query string :param filter: [Hash] Filter options. See examples for usage. Accepts a dict, with filter names and their values. For repeating filter names pass in a list of the values to that filter name, e.g., `{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`. See https://github.com/CrossRef/rest-api-doc for filter names and their descriptions and :func:`~habanero.Crossref.filter_names` and :func:`~habanero.Crossref.filter_details` :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relavant when searching with specific dois. Default: 20. Max: 1000 :param sample: [Fixnum] Number of random results to return. when you use the sample parameter, the limit and offset parameters are ignored. Max: 100 :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort order will be by the relevance score. If no query is included, then the sort order will be by DOI update date. See sorting_ for possible values. :param order: [String] Sort order, one of 'asc' or 'desc' :param facet: [Boolean/String] Set to `true` to include facet results (default: false). Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`. See Facets_ for options. :param select: [String/list(Strings)] Crossref metadata records can be quite large. Sometimes you just want a few elements from the schema. You can "select" a subset of elements to return. This can make your API calls much more efficient. Not clear yet which fields are allowed here. :param cursor: [String] Cursor character string to do deep paging. Default is None. Pass in '*' to start deep paging. Any combination of query, filters and facets may be used with deep paging cursors. While rows may be specified along with cursor, offset and sample cannot be used. See https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md :param cursor_max: [Fixnum] Max records to retrieve. Only used when cursor param used. Because deep paging can result in continuous requests until all are retrieved, use this parameter to set a maximum number of records. Of course, if there are less records found than this value, you will get only those found. :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples and FieldQueries_) :return: A dict Usage:: from habanero import Crossref cr = Crossref() cr.works() cr.works(ids = '10.1371/journal.pone.0033693') dois = ['10.1371/journal.pone.0033693', ] cr.works(ids = dois) x = cr.works(query = "ecology") x['status'] x['message-type'] x['message-version'] x['message'] x['message']['total-results'] x['message']['items-per-page'] x['message']['query'] x['message']['items'] x = cr.works(filter = {'has_full_text': True}) x x = cr.works(filter = {'has_full_text': True}) [ z['DOI'] for z in x['message']['items'] ] [ {"doi": z['DOI'], "url": z['URL']} for z in x['message']['items'] ] for i in x['message']['items']: print i['DOI'] cr.works(filter = {'has_full_text': True}) cr.works(filter = {'has_funder': True, 'has_full_text': True}) cr.works(filter = {'award_number': 'CBET-0756451', 'award_funder': '10.13039/100000001'}) x = cr.works(filter = {'award_funder': ['10.13039/100004440', '10.13039/100000861']}, limit = 100) map(lambda z:z['funder'][0]['DOI'], x['message']['items']) cr.works(query = "widget", cursor = "*", cursor_max = 100) res = cr.works(query = "octopus", cursor = "*", limit = 500) sum([ len(z['message']['items']) for z in res ]) res = cr.works(query = "extravagant", cursor = "*", limit = 50, cursor_max = 500) sum([ len(z['message']['items']) for z in res ]) res = cr.works(query = "widget", cursor = "*", cursor_max = 100) sum([ len(z['message']['items']) for z in res ]) res = cr.works(query = "ecology", cursor = "*", cursor_max = 10000, limit = 1000) sum([ len(z['message']['items']) for z in res ]) items = [ z['message']['items'] for z in res ] items = [ item for sublist in items for item in sublist ] [ z['DOI'] for z in items ][0:50] res = cr.works(query = "ecology", query_author = 'carl boettiger') [ x['author'][0]['family'] for x in res['message']['items'] ] cr.works(query = "ecology", select = "DOI,title") cr.works(query = "ecology", select = ["DOI","title"]) ''' if ids.__class__.__name__ != 'NoneType': return request(self.mailto, self.base_url, "/works/", ids, query, filter, offset, limit, sample, sort, order, facet, select, None, None, None, None, **kwargs) else: return Request(self.mailto, self.base_url, "/works/", query, filter, offset, limit, sample, sort, order, facet, select, cursor, cursor_max, None, **kwargs).do_request()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prefixes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'works'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '40', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '41', 'type': 'dictionary_splat_pattern', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '43', 'type': 'block', 'children': ['44', '46', '53']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': '\'\'\'\n Search Crossref prefixes\n :param ids: [Array] DOIs (digital object identifier) or other identifiers\n :param filter: [Hash] Filter options. See examples for usage.\n Accepts a dict, with filter names and their values. For repeating filter names\n pass in a list of the values to that filter name, e.g.,\n `{\'award_funder\': [\'10.13039/100004440\', \'10.13039/100000861\']}`.\n See https://github.com/CrossRef/rest-api-doc\n for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`\n and :func:`~habanero.Crossref.filter_details`\n :param offset: [Fixnum] Number of record to start at, from 1 to 10000\n :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000\n :param sample: [Fixnum] Number of random results to return. when you use the sample parameter,\n the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100\n :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort\n order will be by the relevance score. If no query is included, then the sort order\n will be by DOI update date. See sorting_ for possible values.\n :param order: [String] Sort order, one of \'asc\' or \'desc\'\n :param facet: [Boolean/String] Set to `true` to include facet results (default: false).\n Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`\n See Facets_ for options.\n :param select: [String/list(Strings)] Crossref metadata records can be\n quite large. Sometimes you just want a few elements from the schema. You can "select"\n a subset of elements to return. This can make your API calls much more efficient. Not\n clear yet which fields are allowed here.\n :param works: [Boolean] If true, works returned as well. Default: false\n :param kwargs: additional named arguments passed on to `requests.get`, e.g., field\n queries (see examples and FieldQueries_)\n :return: A dict\n Usage::\n from habanero import Crossref\n cr = Crossref()\n cr.prefixes(ids = "10.1016")\n cr.prefixes(ids = [\'10.1016\',\'10.1371\',\'10.1023\',\'10.4176\',\'10.1093\'])\n cr.prefixes(ids = "10.1016", works = True)\n cr.prefixes(ids = "10.1016", works = True, limit = 3)\n cr.prefixes(ids = "10.1016", works = True, sort = "relevance", order = "asc")\n res = cr.prefixes(ids = "10.1016", works = True, cursor = "*", limit = 200)\n sum([ len(z[\'message\'][\'items\']) for z in res ])\n items = [ z[\'message\'][\'items\'] for z in res ]\n items = [ item for sublist in items for item in sublist ]\n [ z[\'DOI\'] for z in items ][0:50]\n res = cr.prefixes(ids = "10.1371", works = True, query_editor = \'cooper\', filter = {\'type\': \'journal-article\'})\n eds = [ x.get(\'editor\') for x in res[\'message\'][\'items\'] ]\n [ z for z in eds if z is not None ]\n \'\'\''},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'check_kwargs'},{'id': '49', 'type': 'argument_list', 'children': ['50', '52']},{'id': '50', 'type': 'list', 'children': ['51'], 'value': '["query"]'},{'id': '51', 'type': 'string', 'children': [], 'value': '"query"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60', '63', '64', '65', '68', '71', '74', '77', '80', '83', '86', '89', '92', '95', '98', '101']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mailto'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '63', 'type': 'string', 'children': [], 'value': '"/prefixes/"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'works'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'works'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '101', 'type': 'dictionary_splat', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def prefixes(self, ids = None, filter = None, offset = None, limit = None, sample = None, sort = None, order = None, facet = None, works = False, select = None, cursor = None, cursor_max = 5000, **kwargs): ''' Search Crossref prefixes :param ids: [Array] DOIs (digital object identifier) or other identifiers :param filter: [Hash] Filter options. See examples for usage. Accepts a dict, with filter names and their values. For repeating filter names pass in a list of the values to that filter name, e.g., `{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`. See https://github.com/CrossRef/rest-api-doc for filter names and their descriptions and :func:`~habanero.Crossref.filter_names` and :func:`~habanero.Crossref.filter_details` :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000 :param sample: [Fixnum] Number of random results to return. when you use the sample parameter, the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100 :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort order will be by the relevance score. If no query is included, then the sort order will be by DOI update date. See sorting_ for possible values. :param order: [String] Sort order, one of 'asc' or 'desc' :param facet: [Boolean/String] Set to `true` to include facet results (default: false). Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*` See Facets_ for options. :param select: [String/list(Strings)] Crossref metadata records can be quite large. Sometimes you just want a few elements from the schema. You can "select" a subset of elements to return. This can make your API calls much more efficient. Not clear yet which fields are allowed here. :param works: [Boolean] If true, works returned as well. Default: false :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples and FieldQueries_) :return: A dict Usage:: from habanero import Crossref cr = Crossref() cr.prefixes(ids = "10.1016") cr.prefixes(ids = ['10.1016','10.1371','10.1023','10.4176','10.1093']) cr.prefixes(ids = "10.1016", works = True) cr.prefixes(ids = "10.1016", works = True, limit = 3) cr.prefixes(ids = "10.1016", works = True, sort = "relevance", order = "asc") res = cr.prefixes(ids = "10.1016", works = True, cursor = "*", limit = 200) sum([ len(z['message']['items']) for z in res ]) items = [ z['message']['items'] for z in res ] items = [ item for sublist in items for item in sublist ] [ z['DOI'] for z in items ][0:50] res = cr.prefixes(ids = "10.1371", works = True, query_editor = 'cooper', filter = {'type': 'journal-article'}) eds = [ x.get('editor') for x in res['message']['items'] ] [ z for z in eds if z is not None ] ''' check_kwargs(["query"], kwargs) return request(self.mailto, self.base_url, "/prefixes/", ids, query = None, filter = filter, offset = offset, limit = limit, sample = sample, sort = sort, order = order, facet = facet, select = select, works = works, cursor = cursor, cursor_max = cursor_max, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '46']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'types'},{'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': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'works'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '43', 'type': 'integer', 'children': [], 'value': '5000'},{'id': '44', 'type': 'dictionary_splat_pattern', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '46', 'type': 'block', 'children': ['47', '49']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': '\'\'\'\n Search Crossref types\n :param ids: [Array] Type identifier, e.g., journal\n :param query: [String] A query string\n :param filter: [Hash] Filter options. See examples for usage.\n Accepts a dict, with filter names and their values. For repeating filter names\n pass in a list of the values to that filter name, e.g.,\n `{\'award_funder\': [\'10.13039/100004440\', \'10.13039/100000861\']}`.\n See https://github.com/CrossRef/rest-api-doc\n for filter names and their descriptions and :func:`~habanero.Crossref.filter_names`\n and :func:`~habanero.Crossref.filter_details`\n :param offset: [Fixnum] Number of record to start at, from 1 to 10000\n :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000\n :param sample: [Fixnum] Number of random results to return. when you use the sample parameter,\n the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100\n :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort\n order will be by the relevance score. If no query is included, then the sort order\n will be by DOI update date. See sorting_ for possible values.\n :param order: [String] Sort order, one of \'asc\' or \'desc\'\n :param facet: [Boolean/String] Set to `true` to include facet results (default: false).\n Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`\n See Facets_ for options.\n :param select: [String/list(Strings)] Crossref metadata records can be\n quite large. Sometimes you just want a few elements from the schema. You can "select"\n a subset of elements to return. This can make your API calls much more efficient. Not\n clear yet which fields are allowed here.\n :param works: [Boolean] If true, works returned as well. Default: false\n :param kwargs: additional named arguments passed on to `requests.get`, e.g., field\n queries (see examples and FieldQueries_)\n :return: A dict\n Usage::\n from habanero import Crossref\n cr = Crossref()\n cr.types()\n cr.types(ids = "journal")\n cr.types(ids = "journal-article")\n cr.types(ids = "journal", works = True)\n res = cr.types(ids = "journal-article", works = True, query_title = \'gender\', rows = 100)\n [ x.get(\'title\') for x in res[\'message\'][\'items\'] ]\n \'\'\''},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '52', 'type': 'argument_list', 'children': ['53', '56', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mailto'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '59', 'type': 'string', 'children': [], 'value': '"/types/"'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'works'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cursor_max'},{'id': '73', 'type': 'dictionary_splat', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def types(self, ids = None, query = None, filter = None, offset = None, limit = None, sample = None, sort = None, order = None, facet = None, works = False, select = None, cursor = None, cursor_max = 5000, **kwargs): ''' Search Crossref types :param ids: [Array] Type identifier, e.g., journal :param query: [String] A query string :param filter: [Hash] Filter options. See examples for usage. Accepts a dict, with filter names and their values. For repeating filter names pass in a list of the values to that filter name, e.g., `{'award_funder': ['10.13039/100004440', '10.13039/100000861']}`. See https://github.com/CrossRef/rest-api-doc for filter names and their descriptions and :func:`~habanero.Crossref.filter_names` and :func:`~habanero.Crossref.filter_details` :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000 :param sample: [Fixnum] Number of random results to return. when you use the sample parameter, the limit and offset parameters are ignored. This parameter only used when works requested. Max: 100 :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort order will be by the relevance score. If no query is included, then the sort order will be by DOI update date. See sorting_ for possible values. :param order: [String] Sort order, one of 'asc' or 'desc' :param facet: [Boolean/String] Set to `true` to include facet results (default: false). Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*` See Facets_ for options. :param select: [String/list(Strings)] Crossref metadata records can be quite large. Sometimes you just want a few elements from the schema. You can "select" a subset of elements to return. This can make your API calls much more efficient. Not clear yet which fields are allowed here. :param works: [Boolean] If true, works returned as well. Default: false :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples and FieldQueries_) :return: A dict Usage:: from habanero import Crossref cr = Crossref() cr.types() cr.types(ids = "journal") cr.types(ids = "journal-article") cr.types(ids = "journal", works = True) res = cr.types(ids = "journal-article", works = True, query_title = 'gender', rows = 100) [ x.get('title') for x in res['message']['items'] ] ''' return request(self.mailto, self.base_url, "/types/", ids, query, filter, offset, limit, sample, sort, order, facet, select, works, cursor, cursor_max, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'licenses'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'dictionary_splat_pattern', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '28', 'type': 'block', 'children': ['29', '31', '40', '68']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'string', 'children': [], 'value': '\'\'\'\n Search Crossref licenses\n :param query: [String] A query string\n :param offset: [Fixnum] Number of record to start at, from 1 to 10000\n :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000\n :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort\n order will be by the relevance score. If no query is included, then the sort order\n will be by DOI update date. See sorting_ for possible values.\n :param order: [String] Sort order, one of \'asc\' or \'desc\'\n :param facet: [Boolean/String] Set to `true` to include facet results (default: false).\n Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*`\n See Facets_ for options.\n :param kwargs: additional named arguments passed on to `requests.get`, e.g., field\n queries (see examples and FieldQueries_)\n :return: A dict\n Usage::\n from habanero import Crossref\n cr = Crossref()\n cr.licenses()\n cr.licenses(query = "creative")\n \'\'\''},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'check_kwargs'},{'id': '34', 'type': 'argument_list', 'children': ['35', '39']},{'id': '35', 'type': 'list', 'children': ['36', '37', '38'], 'value': '["ids", "filter", "works"]'},{'id': '36', 'type': 'string', 'children': [], 'value': '"ids"'},{'id': '37', 'type': 'string', 'children': [], 'value': '"filter"'},{'id': '38', 'type': 'string', 'children': [], 'value': '"works"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '45', 'type': 'argument_list', 'children': ['46', '49', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mailto'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '52', 'type': 'string', 'children': [], 'value': '"/licenses/"'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'facet'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'dictionary_splat', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'res'}
def licenses(self, query = None, offset = None, limit = None, sample = None, sort = None, order = None, facet = None, **kwargs): ''' Search Crossref licenses :param query: [String] A query string :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000 :param sort: [String] Field to sort on. Note: If the API call includes a query, then the sort order will be by the relevance score. If no query is included, then the sort order will be by DOI update date. See sorting_ for possible values. :param order: [String] Sort order, one of 'asc' or 'desc' :param facet: [Boolean/String] Set to `true` to include facet results (default: false). Optionally, pass a query string, e.g., `facet=type-name:*` or `facet=license=*` See Facets_ for options. :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples and FieldQueries_) :return: A dict Usage:: from habanero import Crossref cr = Crossref() cr.licenses() cr.licenses(query = "creative") ''' check_kwargs(["ids", "filter", "works"], kwargs) res = request(self.mailto, self.base_url, "/licenses/", None, query, None, offset, limit, None, sort, order, facet, None, None, None, None, **kwargs) return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_graph_component'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'block', 'children': ['6', '20', '30', '40', '55']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '11', 'type': 'argument_list', 'children': ['12', '19']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_visit'},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'node_component'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_gen_node_component'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'graph_component'},{'id': '33', 'type': 'dictionary_comprehension', 'children': ['34', '37']},{'id': '34', 'type': 'pair', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '36', 'type': 'list', 'children': [], 'value': '[]'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'graph_component'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_gen_graph_component'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'node_component'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_gen_graph_value'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'graph_component'}
def get_graph_component(graph): components = map(partial(_visit, graph=graph), graph) node_component = dict(_gen_node_component(components)) graph_component = {component: [] for component in components} graph_component.update( dict(_gen_graph_component(graph, node_component, _gen_graph_value))) return graph_component
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pipe_fetchdata'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '30', '40', '48', '58', '67']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_splits'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23', '24']},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '24', 'type': 'dictionary_splat', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cdicts'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get_parsed'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'funcs'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'starmap'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'parse_result'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'gen_items'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'multiplex'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'}
def pipe_fetchdata(context=None, _INPUT=None, conf=None, **kwargs): funcs = get_splits(None, conf, **cdicts(opts, kwargs)) parsed = get_parsed(_INPUT, funcs[0]) results = starmap(parse_result, parsed) items = imap(utils.gen_items, results) _OUTPUT = utils.multiplex(items) return _OUTPUT
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pipe_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '26', '37', '52', '63', '77', '85', '106', '114', '124', '140']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'pass_if'"},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_pass'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_pass'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key_defs'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'DotDict'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'listize'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '51', 'type': 'string', 'children': [], 'value': "'KEY'"},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_value'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_value'},{'id': '61', 'type': 'dictionary_splat', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parse_conf'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72', '75']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'parse_conf'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parse_func'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get_value'},{'id': '75', 'type': 'dictionary_splat', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'parse_conf'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key_defs'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '88', 'type': 'generator_expression', 'children': ['89', '103']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'string', 'children': [], 'value': "'%s%s'"},{'id': '91', 'type': 'tuple', 'children': ['92', '100']},{'id': '92', 'type': 'conditional_expression', 'children': ['93', '94', '99'], 'value': 'if'},{'id': '93', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '98', 'type': 'string', 'children': [], 'value': "'DESC'"},{'id': '99', 'type': 'string', 'children': [], 'value': "''"},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'comparers'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_comparer'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'cmp_func'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'multikeysort'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'comparers'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'comparers'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'},{'id': '127', 'type': 'conditional_expression', 'children': ['128', '129', '130'], 'value': 'if'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '_pass'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'cmp_func'},{'id': '140', 'type': 'return_statement', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'}
def pipe_sort(context=None, _INPUT=None, conf=None, **kwargs): test = kwargs.pop('pass_if', None) _pass = utils.get_pass(test=test) key_defs = imap(DotDict, utils.listize(conf['KEY'])) get_value = partial(utils.get_value, **kwargs) parse_conf = partial(utils.parse_conf, parse_func=get_value, **kwargs) keys = imap(parse_conf, key_defs) order = ('%s%s' % ('-' if k.dir == 'DESC' else '', k.field) for k in keys) comparers = map(get_comparer, order) cmp_func = partial(multikeysort, comparers=comparers) _OUTPUT = _INPUT if _pass else iter(sorted(_INPUT, cmp=cmp_func)) return _OUTPUT
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'asyncPipeStringtokenizer'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '34', '49', '61', '74', '83']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '20', 'type': 'string', 'children': [], 'value': "'delimiter'"},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'to-str'"},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '33', 'type': 'string', 'children': [], 'value': "'delimiter'"},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '37', 'type': 'yield', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'asyncGetSplits'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_INPUT'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '43', 'type': 'dictionary_splat', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cdicts'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'opts'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '52', 'type': 'yield', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'asyncDispatch'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'splits'},{'id': '57', 'type': 'list_splat', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_async_dispatch_funcs'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '64', 'type': 'yield', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'asyncStarMap'},{'id': '67', 'type': 'argument_list', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'maybeDeferred'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'parse_result'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'multiplex'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'returnValue'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_OUTPUT'}
def asyncPipeStringtokenizer(context=None, _INPUT=None, conf=None, **kwargs): conf['delimiter'] = conf.pop('to-str', dict.get(conf, 'delimiter')) splits = yield asyncGetSplits(_INPUT, conf, **cdicts(opts, kwargs)) parsed = yield asyncDispatch(splits, *get_async_dispatch_funcs()) items = yield asyncStarMap(partial(maybeDeferred, parse_result), parsed) _OUTPUT = utils.multiplex(items) returnValue(_OUTPUT)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alphabeta'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'game'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '7', 'type': 'tuple', 'children': ['8', '13']},{'id': '8', 'type': 'unary_operator', 'children': ['9'], 'value': '-'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'player'},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dominoes'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '24', 'type': 'block', 'children': ['25', '27', '42', '114', '176']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'''\n Runs minimax search with alpha-beta pruning on the provided game.\n :param Game game: game to search\n :param tuple alpha_beta: a tuple of two floats that indicate\n the initial values of alpha and beta,\n respectively. The default is (-inf, inf).\n :param callable player: player used to sort moves to be explored.\n Ordering better moves first may significantly\n reduce the amount of moves that need to be\n explored. The identity player is the default.\n '''"},{'id': '27', 'type': 'if_statement', 'children': ['28', '33']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': 'is'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'game'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'expression_list', 'children': ['36', '37']},{'id': '36', 'type': 'list', 'children': [], 'value': '[]'},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'game'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'points'},{'id': '42', 'type': 'if_statement', 'children': ['43', '48', '80']},{'id': '43', 'type': 'binary_operator', 'children': ['44', '47'], 'value': '%'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'game'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'turn'},{'id': '47', 'type': 'integer', 'children': [], 'value': '2'},{'id': '48', 'type': 'block', 'children': ['49', '56', '62']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'best_value'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lt'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '65', 'type': 'lambda', 'children': ['66', '69']},{'id': '66', 'type': 'lambda_parameters', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '69', 'type': 'tuple', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82', '90', '96']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'best_value'},{'id': '85', 'type': 'unary_operator', 'children': ['86'], 'value': '-'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'gt'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '99', 'type': 'lambda', 'children': ['100', '103']},{'id': '100', 'type': 'lambda_parameters', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '103', 'type': 'tuple', 'children': ['104', '111']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '106', 'type': 'argument_list', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ab'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'for_statement', 'children': ['115', '118', '123']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'move'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'new_game'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'make_moves'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'game'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'player'},{'id': '123', 'type': 'block', 'children': ['124', '135']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'moves'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'alphabeta'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'new_game'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'player'},{'id': '135', 'type': 'if_statement', 'children': ['136', '141']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'best_value'},{'id': '141', 'type': 'block', 'children': ['142', '146', '150', '158', '166']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'best_value'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'best_moves'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'moves'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'best_moves'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'move'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'best_value'},{'id': '166', 'type': 'if_statement', 'children': ['167', '174']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '171'], 'value': '<='},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'alpha_beta'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'break_statement', 'children': []},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'expression_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'best_moves'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'best_value'}
def alphabeta(game, alpha_beta=(-float('inf'), float('inf')), player=dominoes.players.identity): ''' Runs minimax search with alpha-beta pruning on the provided game. :param Game game: game to search :param tuple alpha_beta: a tuple of two floats that indicate the initial values of alpha and beta, respectively. The default is (-inf, inf). :param callable player: player used to sort moves to be explored. Ordering better moves first may significantly reduce the amount of moves that need to be explored. The identity player is the default. ''' if game.result is not None: return [], game.result.points if game.turn % 2: best_value = float('inf') op = operator.lt update = lambda ab, v: (ab[0], min(ab[1], v)) else: best_value = -float('inf') op = operator.gt update = lambda ab, v: (max(ab[0], v), ab[1]) for move, new_game in make_moves(game, player): moves, value = alphabeta(new_game, alpha_beta, player) if op(value, best_value): best_value = value best_moves = moves best_moves.insert(0, move) alpha_beta = update(alpha_beta, best_value) if alpha_beta[1] <= alpha_beta[0]: break return best_moves, best_value
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '25', '36', '63', '74', '85', '109', '113', '117', '128', '148', '202']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'first_element'},{'id': '19', 'type': 'subscript', 'children': ['20', '24']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'function_definition', 'children': ['26', '27', '28']},{'id': '26', 'type': 'function_name', 'children': [], 'value': '_keys'},{'id': '27', 'type': 'parameters', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'first_element'},{'id': '36', 'type': 'function_definition', 'children': ['37', '38', '41']},{'id': '37', 'type': 'function_name', 'children': [], 'value': '_get'},{'id': '38', 'type': 'parameters', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'block', 'children': ['42', '61']},{'id': '42', 'type': 'try_statement', 'children': ['43', '55']},{'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': 'tmp'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'except_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '60', 'type': 'string', 'children': [], 'value': "' '"},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tmp'},{'id': '63', 'type': 'if_statement', 'children': ['64', '71']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '68'], 'value': 'or'},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '67', 'type': 'None', 'children': []},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '70', 'type': 'dictionary', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_keys'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'if_statement', 'children': ['86', '93', '98']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'and'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '89', 'type': 'None', 'children': []},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '98', 'type': 'elif_clause', 'children': ['99', '102']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_keys'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '112', 'type': 'string', 'children': [], 'value': '""'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '116', 'type': 'list', 'children': [], 'value': '[]'},{'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '147'], 'value': '+'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': '","'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'list_comprehension', 'children': ['140', '144']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '147', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '151', 'type': 'block', 'children': ['152', '156', '182']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '155', 'type': 'list', 'children': [], 'value': '[]'},{'id': '156', 'type': 'for_statement', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'try_statement', 'children': ['161', '173']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'subscript', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'attribute'},{'id': '173', 'type': 'except_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': '"None"'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '201'], 'value': '+'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '+'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'string', 'children': [], 'value': '","'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'list_comprehension', 'children': ['194', '198']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '198', 'type': 'for_in_clause', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '201', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '202', 'type': 'return_statement', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'table'}
def csv(cls, d, order=None, header=None, sort_keys=True): first_element = list(d)[0] def _keys(): return list(d[first_element]) def _get(element, key): try: tmp = str(d[element][key]) except: tmp = ' ' return tmp if d is None or d == {}: return None if order is None: order = _keys() if header is None and order is not None: header = order elif header is None: header = _keys() table = "" content = [] for attribute in order: content.append(attribute) table = table + ",".join([str(e) for e in content]) + "\n" for job in d: content = [] for attribute in order: try: content.append(d[job][attribute]) except: content.append("None") table = table + ",".join([str(e) for e in content]) + "\n" return table
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'deauthorize_application'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10', '48']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'facebook'},{'id': '10', 'type': 'block', 'children': ['11', '32', '38', '44']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'user'},{'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': 'User'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'facebook_id'},{'id': '23', 'type': 'attribute', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'facebook'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'signed_request'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'authorized'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'HttpResponse'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '56', 'type': 'integer', 'children': [], 'value': '400'}
def deauthorize_application(request): if request.facebook: user = User.objects.get( facebook_id = request.facebook.signed_request.user.id ) user.authorized = False user.save() return HttpResponse() else: return HttpResponse(status=400)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_send_response'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'payloadsByTopicPart'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '8', 'type': 'block', 'children': ['9', '50', '98', '122', '267', '271', '412', '471', '479']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '16']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_deliver_result'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'd_list'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'd_list'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '28', '35']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'Deferred'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '35', 'type': 'else_clause', 'children': ['36']},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '42']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'called'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']},{'id': '51', 'type': 'function_name', 'children': [], 'value': '_do_retry'},{'id': '52', 'type': 'parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'payloads'},{'id': '54', 'type': 'block', 'children': ['55', '79', '85', '96']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '58', 'type': 'call', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'send_produce_request'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '71', '76']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'payloads'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'acks'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'req_acks'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ack_timeout'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'fail_on_error'},{'id': '78', 'type': 'False', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '84'], 'value': '+='},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_req_attempts'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'addBoth'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94', '95']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '_handle_send_response'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'payloadsByTopicPart'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '103']},{'id': '99', 'type': 'function_name', 'children': [], 'value': '_cancel_retry'},{'id': '100', 'type': 'parameters', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '103', 'type': 'block', 'children': ['104', '110', '120']},{'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': 'dc'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cancel'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '113', 'type': 'argument_list', 'children': ['114', '119']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '122', 'type': 'function_definition', 'children': ['123', '124', '126']},{'id': '123', 'type': 'function_name', 'children': [], 'value': '_check_retry_payloads'},{'id': '124', 'type': 'parameters', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'failed_payloads_with_errs'},{'id': '126', 'type': 'block', 'children': ['127', '163', '169', '194', '202', '210', '216', '245', '258', '265']},{'id': '127', 'type': 'if_statement', 'children': ['128', '135']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': '>='},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_req_attempts'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_max_attempts'},{'id': '135', 'type': 'block', 'children': ['136', '162']},{'id': '136', 'type': 'for_statement', 'children': ['137', '140', '141']},{'id': '137', 'type': 'pattern_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'failed_payloads_with_errs'},{'id': '141', 'type': 'block', 'children': ['142', '154']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 't_and_p'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'TopicAndPartition'},{'id': '147', 'type': 'argument_list', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '157', 'type': 'argument_list', 'children': ['158', '161']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 't_and_p'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '162', 'type': 'return_statement', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'Deferred'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '172', 'type': 'call', 'children': ['173', '180']},{'id': '173', 'type': 'attribute', 'children': ['174', '179']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'reactor'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'callLater'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184', '187']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_retry_interval'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '187', 'type': 'list_comprehension', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '193']},{'id': '190', 'type': 'pattern_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'augmented_assignment', 'children': ['196', '199'], 'value': '*='},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_retry_interval'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'RETRY_INTERVAL_FACTOR'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'addErrback'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_cancel_retry'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'reset_topics'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '215', 'type': 'argument_list', 'children': []},{'id': '216', 'type': 'for_statement', 'children': ['217', '220', '221']},{'id': '217', 'type': 'pattern_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'if_statement', 'children': ['223', '235']},{'id': '223', 'type': '()', 'children': ['224']},{'id': '224', 'type': 'boolean_operator', 'children': ['225', '230'], 'value': 'or'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'NotLeaderForPartitionError'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'UnknownTopicOrPartitionError'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'reset_topics'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'payload'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '245', 'type': 'if_statement', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'reset_topics'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'reset_topic_metadata'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'list_splat', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'reset_topics'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'addCallback'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': '_do_retry'},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '270', 'type': 'list', 'children': [], 'value': '[]'},{'id': '271', 'type': 'if_statement', 'children': ['272', '274', '308']},{'id': '272', 'type': 'not_operator', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '274', 'type': 'block', 'children': ['275', '297', '307']},{'id': '275', 'type': 'if_statement', 'children': ['276', '281', '286']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '=='},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'req_acks'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'PRODUCER_ACK_NOT_REQUIRED'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'else_clause', 'children': ['287']},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'Failure'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'NoResponseError'},{'id': '296', 'type': 'argument_list', 'children': []},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '300', 'type': 'argument_list', 'children': ['301', '306']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '307', 'type': 'return_statement', 'children': []},{'id': '308', 'type': 'elif_clause', 'children': ['309', '314']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '311', 'type': 'argument_list', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'Failure'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'if_statement', 'children': ['316', '323', '386']},{'id': '316', 'type': 'not_operator', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'FailedPayloadsError'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'if_statement', 'children': ['325', '331', '354']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'KafkaError'},{'id': '331', 'type': 'block', 'children': ['332', '340']},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'assignment', 'children': ['334', '337']},{'id': '334', 'type': 'pattern_list', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '337', 'type': 'expression_list', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '339', 'type': 'list', 'children': [], 'value': '[]'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '343', 'type': 'list_comprehension', 'children': ['344', '347']},{'id': '344', 'type': 'tuple', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '347', 'type': 'for_in_clause', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'payloadsByTopicPart'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '353', 'type': 'argument_list', 'children': []},{'id': '354', 'type': 'else_clause', 'children': ['355']},{'id': '355', 'type': 'block', 'children': ['356', '375', '385']},{'id': '356', 'type': 'if_statement', 'children': ['357', '364']},{'id': '357', 'type': 'not_operator', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'tid_CancelledError'},{'id': '364', 'type': 'block', 'children': ['365']},{'id': '365', 'type': 'expression_statement', 'children': ['366']},{'id': '366', 'type': 'call', 'children': ['367', '370']},{'id': '367', 'type': 'attribute', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '370', 'type': 'argument_list', 'children': ['371', '374']},{'id': '371', 'type': 'concatenated_string', 'children': ['372', '373']},{'id': '372', 'type': 'string', 'children': [], 'value': '"Unexpected failure: %r in "'},{'id': '373', 'type': 'string', 'children': [], 'value': '"_handle_send_response"'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '378', 'type': 'argument_list', 'children': ['379', '384']},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '383', 'type': 'argument_list', 'children': []},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '385', 'type': 'return_statement', 'children': []},{'id': '386', 'type': 'else_clause', 'children': ['387']},{'id': '387', 'type': 'block', 'children': ['388', '392', '402']},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'assignment', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '392', 'type': 'expression_statement', 'children': ['393']},{'id': '393', 'type': 'assignment', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '395', 'type': 'subscript', 'children': ['396', '401']},{'id': '396', 'type': 'attribute', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '401', 'type': 'integer', 'children': [], 'value': '0'},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'assignment', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '405', 'type': 'subscript', 'children': ['406', '411']},{'id': '406', 'type': 'attribute', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'failure'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '411', 'type': 'integer', 'children': [], 'value': '1'},{'id': '412', 'type': 'for_statement', 'children': ['413', '414', '415']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '415', 'type': 'block', 'children': ['416', '428', '438']},{'id': '416', 'type': 'expression_statement', 'children': ['417']},{'id': '417', 'type': 'assignment', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 't_and_p'},{'id': '419', 'type': 'call', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'TopicAndPartition'},{'id': '421', 'type': 'argument_list', 'children': ['422', '425']},{'id': '422', 'type': 'attribute', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'topic'},{'id': '425', 'type': 'attribute', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'partition'},{'id': '428', 'type': 'expression_statement', 'children': ['429']},{'id': '429', 'type': 'assignment', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 't_and_p_err'},{'id': '431', 'type': 'call', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': '_check_error'},{'id': '433', 'type': 'argument_list', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '435', 'type': 'keyword_argument', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'raiseException'},{'id': '437', 'type': 'False', 'children': []},{'id': '438', 'type': 'if_statement', 'children': ['439', '441', '454']},{'id': '439', 'type': 'not_operator', 'children': ['440']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 't_and_p_err'},{'id': '441', 'type': 'block', 'children': ['442', '448']},{'id': '442', 'type': 'expression_statement', 'children': ['443']},{'id': '443', 'type': 'assignment', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'd_list'},{'id': '445', 'type': 'subscript', 'children': ['446', '447']},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'deferredsByTopicPart'},{'id': '447', 'type': 'identifier', 'children': [], 'value': 't_and_p'},{'id': '448', 'type': 'expression_statement', 'children': ['449']},{'id': '449', 'type': 'call', 'children': ['450', '451']},{'id': '450', 'type': 'identifier', 'children': [], 'value': '_deliver_result'},{'id': '451', 'type': 'argument_list', 'children': ['452', '453']},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'd_list'},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '454', 'type': 'else_clause', 'children': ['455']},{'id': '455', 'type': 'block', 'children': ['456', '462']},{'id': '456', 'type': 'expression_statement', 'children': ['457']},{'id': '457', 'type': 'assignment', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '459', 'type': 'subscript', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'payloadsByTopicPart'},{'id': '461', 'type': 'identifier', 'children': [], 'value': 't_and_p'},{'id': '462', 'type': 'expression_statement', 'children': ['463']},{'id': '463', 'type': 'call', 'children': ['464', '467']},{'id': '464', 'type': 'attribute', 'children': ['465', '466']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '467', 'type': 'argument_list', 'children': ['468']},{'id': '468', 'type': 'tuple', 'children': ['469', '470']},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '470', 'type': 'identifier', 'children': [], 'value': 't_and_p_err'},{'id': '471', 'type': 'if_statement', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '473', 'type': 'block', 'children': ['474']},{'id': '474', 'type': 'return_statement', 'children': ['475']},{'id': '475', 'type': 'call', 'children': ['476', '477']},{'id': '476', 'type': 'identifier', 'children': [], 'value': '_check_retry_payloads'},{'id': '477', 'type': 'argument_list', 'children': ['478']},{'id': '478', 'type': 'identifier', 'children': [], 'value': 'failed_payloads'},{'id': '479', 'type': 'return_statement', 'children': []}
def _handle_send_response(self, result, payloadsByTopicPart, deferredsByTopicPart): def _deliver_result(d_list, result=None): for d in d_list: if not isinstance(d, Deferred): _deliver_result(d, result) else: if not d.called: d.callback(result) def _do_retry(payloads): d = self.client.send_produce_request( payloads, acks=self.req_acks, timeout=self.ack_timeout, fail_on_error=False) self._req_attempts += 1 d.addBoth(self._handle_send_response, payloadsByTopicPart, deferredsByTopicPart) return d def _cancel_retry(failure, dc): dc.cancel() _deliver_result(deferredsByTopicPart.values(), failure) return failure def _check_retry_payloads(failed_payloads_with_errs): if self._req_attempts >= self._max_attempts: for p, f in failed_payloads_with_errs: t_and_p = TopicAndPartition(p.topic, p.partition) _deliver_result(deferredsByTopicPart[t_and_p], f) return d = Deferred() dc = self.client.reactor.callLater( self._retry_interval, d.callback, [p for p, f in failed_payloads]) self._retry_interval *= self.RETRY_INTERVAL_FACTOR d.addErrback(_cancel_retry, dc) reset_topics = set() for payload, e in failed_payloads: if (isinstance(e, NotLeaderForPartitionError) or isinstance(e, UnknownTopicOrPartitionError)): reset_topics.add(payload.topic) if reset_topics: self.client.reset_topic_metadata(*reset_topics) d.addCallback(_do_retry) return d failed_payloads = [] if not result: if self.req_acks == PRODUCER_ACK_NOT_REQUIRED: result = None else: result = Failure(NoResponseError()) _deliver_result(deferredsByTopicPart.values(), result) return elif isinstance(result, Failure): if not result.check(FailedPayloadsError): if result.check(KafkaError): failure, result = result, [] failed_payloads = [(p, failure) for p in payloadsByTopicPart.values()] else: if not result.check(tid_CancelledError): log.error("Unexpected failure: %r in " "_handle_send_response", result) _deliver_result(deferredsByTopicPart.values(), result) return else: failure = result result = failure.value.args[0] failed_payloads = failure.value.args[1] for res in result: t_and_p = TopicAndPartition(res.topic, res.partition) t_and_p_err = _check_error(res, raiseException=False) if not t_and_p_err: d_list = deferredsByTopicPart[t_and_p] _deliver_result(d_list, res) else: p = payloadsByTopicPart[t_and_p] failed_payloads.append((p, t_and_p_err)) if failed_payloads: return _check_retry_payloads(failed_payloads) return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ordering_url'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '6', 'type': 'block', 'children': ['7', '15', '19', '31', '50', '59', '71', '78', '117', '121', '192', '203']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'request'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '18', 'type': 'string', 'children': [], 'value': '""'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '22', 'type': 'call', 'children': ['23', '30']},{'id': '23', 'type': 'attribute', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'copy'},{'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': 'ordering'},{'id': '34', 'type': 'call', 'children': ['35', '48']},{'id': '35', 'type': 'attribute', 'children': ['36', '47']},{'id': '36', 'type': 'call', 'children': ['37', '44']},{'id': '37', 'type': 'attribute', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'GET'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': '"order"'},{'id': '46', 'type': 'string', 'children': [], 'value': '""'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': '","'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': '_get_ordering_field_lookup'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '62']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'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': 'ordering'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_default_ordering'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'merged_ordering'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '85']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ordering_field'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'get_ordering_fields_lookups'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'if_statement', 'children': ['87', '109']},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '97'], 'value': 'and'},{'id': '88', 'type': '()', 'children': ['89']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '96'], 'value': 'not'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ordering_field'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '97', 'type': '()', 'children': ['98']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '108'], 'value': 'not'},{'id': '99', 'type': '()', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'},{'id': '101', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ordering_field'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'merged_ordering'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ordering_field'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'new_ordering'},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'merged_ordering'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'if_statement', 'children': ['126', '139']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '133'], 'value': '=='},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '153', '176']},{'id': '141', 'type': 'boolean_operator', 'children': ['142', '148'], 'value': 'or'},{'id': '142', 'type': '()', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '=='},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '148', 'type': 'not_operator', 'children': ['149']},{'id': '149', 'type': '()', 'children': ['150']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'in'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '153', 'type': 'block', 'children': ['154', '163']},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'in'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ordering'},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '162', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'new_ordering'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '176', 'type': 'else_clause', 'children': ['177']},{'id': '177', 'type': 'block', 'children': ['178', '182']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '181', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'new_ordering'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'},{'id': '190', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '197']},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '196', 'type': 'string', 'children': [], 'value': '"order"'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': '","'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'new_ordering'},{'id': '203', 'type': 'return_statement', 'children': ['204']},{'id': '204', 'type': 'tuple', 'children': ['205', '217']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '209'], 'value': '+'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '+'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '208', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'safe'},{'id': '216', 'type': 'string', 'children': [], 'value': '","'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'direction'}
def ordering_url(self, field_name): path = self.request.path direction = "" query_params = self.request.GET.copy() ordering = self.request.GET.get("order", "").split(",") field = self._get_ordering_field_lookup(field_name) if not ordering: ordering = self.get_default_ordering() merged_ordering = list(ordering) for ordering_field in self.get_ordering_fields_lookups(): if (ordering_field.lstrip("-") not in ordering) and ( ("-" + ordering_field.lstrip("-")) not in ordering ): merged_ordering.append(ordering_field) new_ordering = [] for item in merged_ordering: if item.lstrip("-") == field.lstrip("-"): if (item[0] == "-") or not (item in ordering): if item in ordering: direction = "desc" new_ordering.insert(0, item.lstrip("-")) else: direction = "asc" new_ordering.insert(0, "-" + item) query_params["order"] = ",".join(new_ordering) return (path + "?" + query_params.urlencode(safe=","), direction)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_maf'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'optional_cols'},{'id': '7', 'type': 'list', 'children': [], 'value': '[]'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'variant_ascending_position_sort_key'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '34', '51', '55', '59', '63', '327']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'maf_df'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'load_maf_dataframe'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '31']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '34', 'type': 'if_statement', 'children': ['35', '43']},{'id': '35', 'type': 'boolean_operator', 'children': ['36', '42'], 'value': 'and'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '=='},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'maf_df'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'},{'id': '49', 'type': 'string', 'children': [], 'value': '"Empty MAF file %s"'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ensembl_objects'},{'id': '54', 'type': 'dictionary', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '58', 'type': 'list', 'children': [], 'value': '[]'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '62', 'type': 'dictionary', 'children': []},{'id': '63', 'type': 'for_statement', 'children': ['64', '67', '72']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'maf_df'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'iterrows'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'block', 'children': ['73', '79', '110', '116', '122', '128', '176', '231', '250', '301', '320']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'Chromosome'},{'id': '79', 'type': 'if_statement', 'children': ['80', '84']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '84', 'type': 'block', 'children': ['85', '92']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'error_message'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': '"Invalid contig name: %s"'},{'id': '90', 'type': 'tuple', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '92', 'type': 'if_statement', 'children': ['93', '94', '100']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'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': 'identifier', 'children': [], 'value': 'error_message'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102', '109']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'error_message'},{'id': '109', 'type': 'continue_statement', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Start_Position'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'Reference_Allele'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'NCBI_Build'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132', '139']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'in'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'ensembl_objects'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ensembl'},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ensembl_objects'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141', '163', '170']},{'id': '141', 'type': 'if_statement', 'children': ['142', '147', '154']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'reference_name'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '%'},{'id': '152', 'type': 'string', 'children': [], 'value': '"B%d"'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'reference_name'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ensembl'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'infer_genome'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'reference_name'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ensembl_objects'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ncbi_build'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ensembl'},{'id': '176', 'type': 'if_statement', 'children': ['177', '182', '189']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': '!='},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Tumor_Seq_Allele1'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'Tumor_Seq_Allele1'},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191', '225']},{'id': '191', 'type': 'if_statement', 'children': ['192', '197']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': '=='},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'Tumor_Seq_Allele2'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '197', 'type': 'block', 'children': ['198', '207']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'error_message'},{'id': '201', 'type': '()', 'children': ['202']},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '%'},{'id': '203', 'type': 'string', 'children': [], 'value': '"Both tumor alleles agree with reference %s: %s"'},{'id': '204', 'type': 'tuple', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '207', 'type': 'if_statement', 'children': ['208', '209', '215']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'raise_on_error'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'raise_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'error_message'},{'id': '215', 'type': 'else_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217', '224']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'error_message'},{'id': '224', 'type': 'continue_statement', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'Tumor_Seq_Allele2'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'Variant'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238', '239', '243', '247']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'contig'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'alt'},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'ensembl'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ensembl'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '255']},{'id': '252', 'type': 'subscript', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '255', 'type': 'dictionary', 'children': ['256', '261', '266', '271', '276', '281', '286', '291', '296']},{'id': '256', 'type': 'pair', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'Hugo_Symbol'"},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Hugo_Symbol'},{'id': '261', 'type': 'pair', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'Center'"},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'Center'},{'id': '266', 'type': 'pair', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': "'Strand'"},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'Strand'},{'id': '271', 'type': 'pair', 'children': ['272', '273']},{'id': '272', 'type': 'string', 'children': [], 'value': "'Variant_Classification'"},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'Variant_Classification'},{'id': '276', 'type': 'pair', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': "'Variant_Type'"},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'Variant_Type'},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'dbSNP_RS'"},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'dbSNP_RS'},{'id': '286', 'type': 'pair', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': "'dbSNP_Val_Status'"},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'dbSNP_Val_Status'},{'id': '291', 'type': 'pair', 'children': ['292', '293']},{'id': '292', 'type': 'string', 'children': [], 'value': "'Tumor_Sample_Barcode'"},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'Tumor_Sample_Barcode'},{'id': '296', 'type': 'pair', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': "'Matched_Norm_Sample_Barcode'"},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'Matched_Norm_Sample_Barcode'},{'id': '301', 'type': 'for_statement', 'children': ['302', '303', '304']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'optional_col'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'optional_cols'},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'if_statement', 'children': ['306', '309']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'in'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'optional_col'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '317']},{'id': '312', 'type': 'subscript', 'children': ['313', '316']},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'optional_col'},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'optional_col'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '327', 'type': 'return_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'VariantCollection'},{'id': '330', 'type': 'argument_list', 'children': ['331', '334', '340', '343']},{'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'source_to_metadata_dict'},{'id': '336', 'type': 'dictionary', 'children': ['337']},{'id': '337', 'type': 'pair', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'distinct'}
def load_maf( path, optional_cols=[], sort_key=variant_ascending_position_sort_key, distinct=True, raise_on_error=True, encoding=None): maf_df = load_maf_dataframe(path, raise_on_error=raise_on_error, encoding=encoding) if len(maf_df) == 0 and raise_on_error: raise ValueError("Empty MAF file %s" % path) ensembl_objects = {} variants = [] metadata = {} for _, x in maf_df.iterrows(): contig = x.Chromosome if isnull(contig): error_message = "Invalid contig name: %s" % (contig,) if raise_on_error: raise ValueError(error_message) else: logging.warn(error_message) continue start_pos = x.Start_Position ref = x.Reference_Allele ncbi_build = x.NCBI_Build if ncbi_build in ensembl_objects: ensembl = ensembl_objects[ncbi_build] else: if isinstance(ncbi_build, int): reference_name = "B%d" % ncbi_build else: reference_name = str(ncbi_build) ensembl = infer_genome(reference_name) ensembl_objects[ncbi_build] = ensembl if x.Tumor_Seq_Allele1 != ref: alt = x.Tumor_Seq_Allele1 else: if x.Tumor_Seq_Allele2 == ref: error_message = ( "Both tumor alleles agree with reference %s: %s" % ( ref, x,)) if raise_on_error: raise ValueError(error_message) else: logging.warn(error_message) continue alt = x.Tumor_Seq_Allele2 variant = Variant( contig, start_pos, str(ref), str(alt), ensembl=ensembl) metadata[variant] = { 'Hugo_Symbol': x.Hugo_Symbol, 'Center': x.Center, 'Strand': x.Strand, 'Variant_Classification': x.Variant_Classification, 'Variant_Type': x.Variant_Type, 'dbSNP_RS': x.dbSNP_RS, 'dbSNP_Val_Status': x.dbSNP_Val_Status, 'Tumor_Sample_Barcode': x.Tumor_Sample_Barcode, 'Matched_Norm_Sample_Barcode': x.Matched_Norm_Sample_Barcode, } for optional_col in optional_cols: if optional_col in x: metadata[variant][optional_col] = x[optional_col] variants.append(variant) return VariantCollection( variants=variants, source_to_metadata_dict={path: metadata}, sort_key=sort_key, distinct=distinct)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_vcf'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '25', '28', '31']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reference_vcf_key'},{'id': '10', 'type': 'string', 'children': [], 'value': '"reference"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'allow_extended_nucleotides'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '**'},{'id': '23', 'type': 'integer', 'children': [], 'value': '10'},{'id': '24', 'type': 'integer', 'children': [], 'value': '5'},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'variant_ascending_position_sort_key'},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '41', '48', '157', '164', '170', '181', '204', '233']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'require_string'},{'id': '38', 'type': 'argument_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '40', 'type': 'string', 'children': [], 'value': '"Path or URL to VCF"'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'parsed_path'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'parse_url_or_path'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '48', 'type': 'if_statement', 'children': ['49', '62']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'and'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parsed_path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '61'], 'value': '!='},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parsed_path'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'string', 'children': [], 'value': '"file"'},{'id': '62', 'type': 'block', 'children': ['63', '76']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'tuple_pattern', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'urllib'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'urlretrieve'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'try_statement', 'children': ['77', '140']},{'id': '77', 'type': 'block', 'children': ['78', '96', '104', '108']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_filename'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'},{'id': '82', 'type': 'string', 'children': [], 'value': '"%s.%s"'},{'id': '83', 'type': 'tuple', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '85', 'type': 'subscript', 'children': ['86', '94']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'parsed_path'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': '"."'},{'id': '94', 'type': 'unary_operator', 'children': ['95'], 'value': '-'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'os'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'new_filename'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'new_filename'},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'load_vcf'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '116', '119', '122', '125', '128', '131', '134', '137']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'reference_vcf_key'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'reference_vcf_key'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'allow_extended_nucleotides'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'allow_extended_nucleotides'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'distinct'},{'id': '140', 'type': 'finally_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142', '150']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"Removing temporary file: %s"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'unlink'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'PyVCFReaderFromPathOrURL'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'infer_genome_from_vcf'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177', '180']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'vcf_reader'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'reference_vcf_key'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'df_iterator'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'read_vcf_into_dataframe'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188', '191', '201']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sample_names'},{'id': '193', 'type': 'conditional_expression', 'children': ['194', '199', '200'], 'value': 'if'},{'id': '194', 'type': 'attribute', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'vcf_reader'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '200', 'type': 'None', 'children': []},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '204', 'type': 'if_statement', 'children': ['205', '206', '227']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'function_definition', 'children': ['208', '209', '212']},{'id': '208', 'type': 'function_name', 'children': [], 'value': 'sample_info_parser'},{'id': '209', 'type': 'parameters', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'unparsed_sample_info_strings'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'format_string'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'return_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'pyvcf_calls_to_sample_info_list'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'vcf_reader'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_parse_samples'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'unparsed_sample_info_strings'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'format_string'},{'id': '226', 'type': 'None', 'children': []},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sample_info_parser'},{'id': '232', 'type': 'None', 'children': []},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'dataframes_to_variant_collection'},{'id': '236', 'type': 'argument_list', 'children': ['237', '238', '241', '251', '254', '257', '267', '270', '279']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'df_iterator'},{'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'source_path'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'info_parser'},{'id': '243', 'type': 'conditional_expression', 'children': ['244', '249', '250'], 'value': 'if'},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'vcf_reader'},{'id': '248', 'type': 'identifier', 'children': [], 'value': '_parse_info'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '250', 'type': 'None', 'children': []},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'only_passing'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'max_variants'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'sample_names'},{'id': '259', 'type': 'conditional_expression', 'children': ['260', '265', '266'], 'value': 'if'},{'id': '260', 'type': 'attribute', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'vcf_reader'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'samples'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'include_info'},{'id': '266', 'type': 'None', 'children': []},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'sample_info_parser'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'sample_info_parser'},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'variant_kwargs'},{'id': '272', 'type': 'dictionary', 'children': ['273', '276']},{'id': '273', 'type': 'pair', 'children': ['274', '275']},{'id': '274', 'type': 'string', 'children': [], 'value': "'ensembl'"},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '276', 'type': 'pair', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': "'allow_extended_nucleotides'"},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'allow_extended_nucleotides'},{'id': '279', 'type': 'keyword_argument', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'variant_collection_kwargs'},{'id': '281', 'type': 'dictionary', 'children': ['282', '285']},{'id': '282', 'type': 'pair', 'children': ['283', '284']},{'id': '283', 'type': 'string', 'children': [], 'value': "'sort_key'"},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '285', 'type': 'pair', 'children': ['286', '287']},{'id': '286', 'type': 'string', 'children': [], 'value': "'distinct'"},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'distinct'}
def load_vcf( path, genome=None, reference_vcf_key="reference", only_passing=True, allow_extended_nucleotides=False, include_info=True, chunk_size=10 ** 5, max_variants=None, sort_key=variant_ascending_position_sort_key, distinct=True): require_string(path, "Path or URL to VCF") parsed_path = parse_url_or_path(path) if parsed_path.scheme and parsed_path.scheme.lower() != "file": (filename, headers) = urllib.request.urlretrieve(path) try: new_filename = "%s.%s" % ( filename, parsed_path.path.split(".")[-1]) os.rename(filename, new_filename) filename = new_filename return load_vcf( filename, genome=genome, reference_vcf_key=reference_vcf_key, only_passing=only_passing, allow_extended_nucleotides=allow_extended_nucleotides, include_info=include_info, chunk_size=chunk_size, max_variants=max_variants, sort_key=sort_key, distinct=distinct) finally: logger.info("Removing temporary file: %s", filename) os.unlink(filename) handle = PyVCFReaderFromPathOrURL(path) handle.close() genome = infer_genome_from_vcf( genome, handle.vcf_reader, reference_vcf_key) df_iterator = read_vcf_into_dataframe( path, include_info=include_info, sample_names=handle.vcf_reader.samples if include_info else None, chunk_size=chunk_size) if include_info: def sample_info_parser(unparsed_sample_info_strings, format_string): return pyvcf_calls_to_sample_info_list( handle.vcf_reader._parse_samples( unparsed_sample_info_strings, format_string, None)) else: sample_info_parser = None return dataframes_to_variant_collection( df_iterator, source_path=path, info_parser=handle.vcf_reader._parse_info if include_info else None, only_passing=only_passing, max_variants=max_variants, sample_names=handle.vcf_reader.samples if include_info else None, sample_info_parser=sample_info_parser, variant_kwargs={ 'ensembl': genome, 'allow_extended_nucleotides': allow_extended_nucleotides}, variant_collection_kwargs={ 'sort_key': sort_key, 'distinct': distinct})
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'top_expression_effect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'expression_levels'},{'id': '6', 'type': 'block', 'children': ['7', '16', '26', '44']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'effect_expression_dict'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'effect_expression'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'expression_levels'},{'id': '16', 'type': 'if_statement', 'children': ['17', '23']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '22'], 'value': '=='},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'effect_expression_dict'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'function_definition', 'children': ['27', '28', '30']},{'id': '27', 'type': 'function_name', 'children': [], 'value': 'key_fn'},{'id': '28', 'type': 'parameters', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'effect_fpkm_pair'},{'id': '30', 'type': 'block', 'children': ['31', '37']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'tuple_pattern', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'effect'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'fpkm'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'effect_fpkm_pair'},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'tuple', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fpkm'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'multi_gene_effect_sort_key'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'effect'},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'subscript', 'children': ['46', '57']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'max'},{'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': 'effect_expression_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': 'identifier', 'children': [], 'value': 'key_fn'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'}
def top_expression_effect(self, expression_levels): effect_expression_dict = self.effect_expression(expression_levels) if len(effect_expression_dict) == 0: return None def key_fn(effect_fpkm_pair): (effect, fpkm) = effect_fpkm_pair return (fpkm, multi_gene_effect_sort_key(effect)) return max(effect_expression_dict.items(), key=key_fn)[0]
{'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': 'callback'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'if_statement', 'children': ['16', '17', '31']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'callback'},{'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': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'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': '__class__'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'}
def sort(self, callback=None): items = self.items if callback: return self.__class__(sorted(items, key=callback)) else: return self.__class__(sorted(items))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'scan_for_spec'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '5', 'type': 'block', 'children': ['6', '20', '29', '44']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '9', 'type': 'call', 'children': ['10', '18']},{'id': '10', 'type': 'attribute', 'children': ['11', '17']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'('"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "')'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'release_line_re'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '29', 'type': 'if_statement', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'Spec'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '">={}"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'matches'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'try_statement', 'children': ['45', '51']},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'Spec'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'keyword'},{'id': '51', 'type': 'except_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'None', 'children': []}
def scan_for_spec(keyword): keyword = keyword.lstrip('(').rstrip(')') matches = release_line_re.findall(keyword) if matches: return Spec(">={}".format(matches[0])) try: return Spec(keyword) except ValueError: return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_students'},{'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': 'gradebook_id'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'section_name'},{'id': '13', 'type': 'string', 'children': [], 'value': "''"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'include_photo'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'include_grade_info'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'include_grade_history'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'include_makeup_grades'},{'id': '25', 'type': 'False', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '65', '69', '118', '141', '207']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '32', 'type': 'argument_list', 'children': ['33', '41', '49', '57']},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'includePhoto'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'include_photo'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'includeGradeInfo'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'include_grade_info'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'includeGradeHistory'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'include_grade_history'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'includeMakeupGrades'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'include_makeup_grades'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '68', 'type': 'string', 'children': [], 'value': "'students/{gradebookId}'"},{'id': '69', 'type': 'if_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'section_name'},{'id': '71', 'type': 'block', 'children': ['72', '83', '109']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get_section_by_name'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'section_name'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'is'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '86', 'type': 'None', 'children': []},{'id': '87', 'type': 'block', 'children': ['88', '97', '104']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'failure_message'},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '96'], 'value': '%'},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'in get_students -- Error: '"},{'id': '95', 'type': 'string', 'children': [], 'value': "'No such section %s'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'section_name'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'critical'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'failure_message'},{'id': '104', 'type': 'raise_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'PyLmodNoSuchSection'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'failure_message'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '112'], 'value': '+='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'/section/{0}'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'group_id'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'student_data'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '125', 'type': 'argument_list', 'children': ['126', '138']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'gradebookId'},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '135'], 'value': 'or'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'gradebook_id'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'gradebook_id'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '141', 'type': 'if_statement', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '143', 'type': 'block', 'children': ['144', '159', '196']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'student_map'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '149', 'type': 'argument_list', 'children': ['150', '153', '156']},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'accountEmail'},{'id': '152', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'displayName'},{'id': '155', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'section'},{'id': '158', 'type': 'string', 'children': [], 'value': "'section'"},{'id': '159', 'type': 'function_definition', 'children': ['160', '161', '163']},{'id': '160', 'type': 'function_name', 'children': [], 'value': 'remap'},{'id': '161', 'type': 'parameters', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'students'},{'id': '163', 'type': 'block', 'children': ['164', '180', '194']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '169', 'type': 'generator_expression', 'children': ['170', '177']},{'id': '170', 'type': 'tuple', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'student_map'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'students'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '177', 'type': 'for_in_clause', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'student_map'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '184', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '189', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "'@mit.edu'"},{'id': '193', 'type': 'string', 'children': [], 'value': "'@MIT.EDU'"},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'newx'},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'list_comprehension', 'children': ['198', '202']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'remap'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '202', 'type': 'for_in_clause', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'student_data'},{'id': '206', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '207', 'type': 'return_statement', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'student_data'},{'id': '210', 'type': 'string', 'children': [], 'value': "'data'"}
def get_students( self, gradebook_id='', simple=False, section_name='', include_photo=False, include_grade_info=False, include_grade_history=False, include_makeup_grades=False ): params = dict( includePhoto=json.dumps(include_photo), includeGradeInfo=json.dumps(include_grade_info), includeGradeHistory=json.dumps(include_grade_history), includeMakeupGrades=json.dumps(include_makeup_grades), ) url = 'students/{gradebookId}' if section_name: group_id, _ = self.get_section_by_name(section_name) if group_id is None: failure_message = ( 'in get_students -- Error: ' 'No such section %s' % section_name ) log.critical(failure_message) raise PyLmodNoSuchSection(failure_message) url += '/section/{0}'.format(group_id) student_data = self.get( url.format( gradebookId=gradebook_id or self.gradebook_id ), params=params, ) if simple: student_map = dict( accountEmail='email', displayName='name', section='section' ) def remap(students): newx = dict((student_map[k], students[k]) for k in student_map) newx['email'] = newx['email'].replace('@mit.edu', '@MIT.EDU') return newx return [remap(x) for x in student_data['data']] return student_data['data']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_staff'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'gradebook_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '33', '81']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'staff_data'},{'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': 'get'},{'id': '17', 'type': 'argument_list', 'children': ['18', '30']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'staff/{gradebookId}'"},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'gradebookId'},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '27'], 'value': 'or'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'gradebook_id'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'gradebook_id'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'if_statement', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '35', 'type': 'block', 'children': ['36', '40', '49', '79']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'simple_list'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'unraveled_list'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'unravel_staff'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'staff_data'},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '56']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'unraveled_list'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '__iter__'},{'id': '55', 'type': 'argument_list', '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': 'simple_list'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'dictionary', 'children': ['64', '69', '74']},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'accountEmail'"},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '68', 'type': 'string', 'children': [], 'value': "'accountEmail'"},{'id': '69', 'type': 'pair', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'displayName'"},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '73', 'type': 'string', 'children': [], 'value': "'displayName'"},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'role'"},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'member'},{'id': '78', 'type': 'string', 'children': [], 'value': "'role'"},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'simple_list'},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'staff_data'},{'id': '84', 'type': 'string', 'children': [], 'value': "'data'"}
def get_staff(self, gradebook_id, simple=False): staff_data = self.get( 'staff/{gradebookId}'.format( gradebookId=gradebook_id or self.gradebook_id ), params=None, ) if simple: simple_list = [] unraveled_list = self.unravel_staff(staff_data) for member in unraveled_list.__iter__(): simple_list.append({ 'accountEmail': member['accountEmail'], 'displayName': member['displayName'], 'role': member['role'], }) return simple_list return staff_data['data']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_course_guide_staff'},{'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': 'course_id'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'block', 'children': ['9', '32']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'staff_data'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '16', 'type': 'argument_list', 'children': ['17', '29']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': "'courseguide/course/{courseId}/staff'"},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'courseId'},{'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'or'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'course_id'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'course_id'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'staff_data'},{'id': '36', 'type': 'string', 'children': [], 'value': "'response'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'docs'"}
def get_course_guide_staff(self, course_id=''): staff_data = self.get( 'courseguide/course/{courseId}/staff'.format( courseId=course_id or self.course_id ), params=None ) return staff_data['response']['docs']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'optimize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '15', '18', '21', '24', '27']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '8', 'type': 'integer', 'children': [], 'value': '100'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'max_seconds'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "'inf'"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'cache_encoded'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'cache_solution'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'clear_cache'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'logging_func'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_print_fitnesses'},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'n_processes'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'block', 'children': ['31', '44', '76', '82', '88', '98', '106', '319']},{'id': '31', 'type': 'if_statement', 'children': ['32', '38']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'Problem'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'problem must be an instance of Problem class'"},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '70']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '>'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n_processes'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'try_statement', 'children': ['50', '62']},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'processes'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'n_processes'},{'id': '62', 'type': 'except_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'NameError'},{'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': 'ImportError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': "'pickle, dill, or multiprocessing library is not available.'"},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '__max_iterations'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_reset'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '91', 'type': 'dictionary', 'children': ['92', '95']},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'solution'"},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'fitness'"},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'population'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'initial_population'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'try_statement', 'children': ['107', '265']},{'id': '107', 'type': 'block', 'children': ['108', '116', '249', '257']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'for_statement', 'children': ['117', '120', '126']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'block', 'children': ['127', '149', '169', '190', '209', '219', '231', '239']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '133']},{'id': '129', 'type': 'pattern_list', 'children': ['130', '131', '132']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fitnesses'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'finished'},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_get_fitnesses'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140', '143', '146']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'problem'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'population'},{'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cache_encoded'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'cache_encoded'},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'cache_solution'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'cache_solution'},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'best_index'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'best_fitness'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '156', 'type': 'argument_list', 'children': ['157', '161']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'fitnesses'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '>'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'best_fitness'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '174', 'type': 'string', 'children': [], 'value': "'fitness'"},{'id': '175', 'type': 'block', 'children': ['176', '182']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '181']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '180', 'type': 'string', 'children': [], 'value': "'fitness'"},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'best_fitness'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '186', 'type': 'string', 'children': [], 'value': "'solution'"},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'best_index'},{'id': '190', 'type': 'if_statement', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'logging_func'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'logging_func'},{'id': '196', 'type': 'argument_list', 'children': ['197', '200', '201', '202', '203', '206']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'population'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'solutions'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fitnesses'},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '205', 'type': 'string', 'children': [], 'value': "'solution'"},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '208', 'type': 'string', 'children': [], 'value': "'fitness'"},{'id': '209', 'type': 'if_statement', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'finished'},{'id': '211', 'type': 'block', 'children': ['212', '218']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'solution_found'},{'id': '217', 'type': 'True', 'children': []},{'id': '218', 'type': 'break_statement', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '229']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '228'], 'value': '>='},{'id': '221', 'type': 'binary_operator', 'children': ['222', '227'], 'value': '-'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '226', 'type': 'argument_list', 'children': []},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'max_seconds'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'break_statement', 'children': []},{'id': '231', 'type': 'if_statement', 'children': ['232', '237']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': '>='},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'max_iterations'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'break_statement', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'population'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'next_population'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'population'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'fitnesses'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '256', 'type': 'string', 'children': [], 'value': "'solution'"},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'best_fitness'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'best_solution'},{'id': '264', 'type': 'string', 'children': [], 'value': "'fitness'"},{'id': '265', 'type': 'finally_clause', 'children': ['266']},{'id': '266', 'type': 'block', 'children': ['267', '298']},{'id': '267', 'type': 'if_statement', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'clear_cache'},{'id': '269', 'type': 'block', 'children': ['270', '276', '282', '290']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': '__encoded_cache'},{'id': '275', 'type': 'dictionary', 'children': []},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': '__solution_cache'},{'id': '281', 'type': 'dictionary', 'children': []},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '286', 'type': 'identifier', 'children': [], 'value': '_get_encoded_key'},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '289', 'type': 'identifier', 'children': [], 'value': '_get_encoded_key_type'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '294', 'type': 'identifier', 'children': [], 'value': '_get_solution_key'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': '_get_solution_key_type'},{'id': '298', 'type': 'try_statement', 'children': ['299', '312']},{'id': '299', 'type': 'block', 'children': ['300', '306']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'terminate'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '311', 'type': 'argument_list', 'children': []},{'id': '312', 'type': 'except_clause', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'assert_statement', 'children': ['316']},{'id': '316', 'type': 'comparison_operator', 'children': ['317', '318'], 'value': 'is'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'pool'},{'id': '318', 'type': 'None', 'children': []},{'id': '319', 'type': 'return_statement', 'children': ['320']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'best_solution'}
def optimize(self, problem, max_iterations=100, max_seconds=float('inf'), cache_encoded=True, cache_solution=False, clear_cache=True, logging_func=_print_fitnesses, n_processes=0): if not isinstance(problem, Problem): raise TypeError('problem must be an instance of Problem class') if n_processes > 0: try: pool = multiprocessing.Pool(processes=n_processes) except NameError: raise ImportError( 'pickle, dill, or multiprocessing library is not available.' ) else: pool = None self.__max_iterations = max_iterations self._reset() best_solution = {'solution': None, 'fitness': None} population = self.initial_population() try: start = time.clock() for self.iteration in itertools.count(1): solutions, fitnesses, finished = self._get_fitnesses( problem, population, cache_encoded=cache_encoded, cache_solution=cache_solution, pool=pool) best_index, best_fitness = max( enumerate(fitnesses), key=operator.itemgetter(1)) if best_fitness > best_solution['fitness']: best_solution['fitness'] = best_fitness best_solution['solution'] = solutions[best_index] if logging_func: logging_func(self.iteration, population, solutions, fitnesses, best_solution['solution'], best_solution['fitness']) if finished: self.solution_found = True break if time.clock() - start >= max_seconds: break if self.iteration >= max_iterations: break population = self.next_population(population, fitnesses) self.best_solution = best_solution['solution'] self.best_fitness = best_solution['fitness'] finally: if clear_cache: self.__encoded_cache = {} self.__solution_cache = {} self._get_encoded_key = self._get_encoded_key_type self._get_solution_key = self._get_solution_key_type try: pool.terminate() pool.close() except AttributeError: assert pool is None return self.best_solution
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'inspect'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '16', '23']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'inspector'},{'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': 'stix2patterns'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'inspector'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'InspectionListener'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'inspector'},{'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': 'inspector'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pattern_data'},{'id': '28', 'type': 'argument_list', 'children': []}
def inspect(self): inspector = stix2patterns.inspector.InspectionListener() self.walk(inspector) return inspector.pattern_data()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'best_kmers'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '9', 'type': 'integer', 'children': [], 'value': '6'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'n_cores'},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'seq_align'},{'id': '18', 'type': 'string', 'children': [], 'value': '"start"'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'trim_seq_len'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '29', '35', '67', '75', '82', '97', '105', '123', '297', '308']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'trim_seq_len'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'block', 'children': ['40', '53']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pad_sequences'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'seq_align'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'maxlen'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'trim_seq_len'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '56', 'type': 'list_comprehension', 'children': ['57', '64']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '63', 'type': 'string', 'children': [], 'value': '""'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'kmer_count'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Xsp'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'csc_matrix'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ElasticNet'},{'id': '87', 'type': 'argument_list', 'children': ['88', '91', '94']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'standardize'},{'id': '93', 'type': 'False', 'children': []},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'n_splits'},{'id': '96', 'type': 'integer', 'children': [], 'value': '3'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Xsp'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'nonzero_kmers'},{'id': '108', 'type': 'call', 'children': ['109', '122']},{'id': '109', 'type': 'attribute', 'children': ['110', '121']},{'id': '110', 'type': 'subscript', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': '!='},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'en'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'coef_'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'function_definition', 'children': ['124', '125', '133']},{'id': '124', 'type': 'function_name', 'children': [], 'value': 'find_next_best'},{'id': '125', 'type': 'parameters', 'children': ['126', '127', '128', '129', '130']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '130', 'type': 'default_parameter', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '132', 'type': 'True', 'children': []},{'id': '133', 'type': 'block', 'children': ['134', '146', '159', '166', '232', '247']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '139']},{'id': '136', 'type': 'pattern_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'f_regression'},{'id': '141', 'type': 'argument_list', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'kmer'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'pval'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'kmer'},{'id': '166', 'type': 'function_definition', 'children': ['167', '168', '174']},{'id': '167', 'type': 'function_name', 'children': [], 'value': 'select_criterion'},{'id': '168', 'type': 'parameters', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '171', 'type': 'default_parameter', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'block', 'children': ['175', '186', '208', '230']},{'id': '175', 'type': 'if_statement', 'children': ['176', '183']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': '<='},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hamming_distance'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'return_statement', 'children': ['185']},{'id': '185', 'type': 'False', 'children': []},{'id': '186', 'type': 'if_statement', 'children': ['187', '205']},{'id': '187', 'type': 'boolean_operator', 'children': ['188', '189'], 'value': 'and'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '204'], 'value': '=='},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'hamming_distance'},{'id': '192', 'type': 'argument_list', 'children': ['193', '198']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '195', 'type': 'slice', 'children': ['196', '197']},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'colon', 'children': []},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '200', 'type': 'slice', 'children': ['201', '202']},{'id': '201', 'type': 'colon', 'children': []},{'id': '202', 'type': 'unary_operator', 'children': ['203'], 'value': '-'},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'integer', 'children': [], 'value': '0'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'return_statement', 'children': ['207']},{'id': '207', 'type': 'False', 'children': []},{'id': '208', 'type': 'if_statement', 'children': ['209', '227']},{'id': '209', 'type': 'boolean_operator', 'children': ['210', '211'], 'value': 'and'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '226'], 'value': '=='},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'hamming_distance'},{'id': '214', 'type': 'argument_list', 'children': ['215', '221']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 's1'},{'id': '217', 'type': 'slice', 'children': ['218', '219']},{'id': '218', 'type': 'colon', 'children': []},{'id': '219', 'type': 'unary_operator', 'children': ['220'], 'value': '-'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 's2'},{'id': '223', 'type': 'slice', 'children': ['224', '225']},{'id': '224', 'type': 'integer', 'children': [], 'value': '1'},{'id': '225', 'type': 'colon', 'children': []},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'False', 'children': []},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'True', 'children': []},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '235', 'type': 'list_comprehension', 'children': ['236', '237', '240']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ckmer'},{'id': '237', 'type': 'for_in_clause', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'ckmer'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '240', 'type': 'if_clause', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'select_criterion'},{'id': '243', 'type': 'argument_list', 'children': ['244', '245', '246']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ckmer'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'kmer'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '247', 'type': 'if_statement', 'children': ['248', '254', '257']},{'id': '248', 'type': 'comparison_operator', 'children': ['249', '253'], 'value': '=='},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '253', 'type': 'integer', 'children': [], 'value': '0'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '257', 'type': 'else_clause', 'children': ['258']},{'id': '258', 'type': 'block', 'children': ['259', '265', '275', '288']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'lm'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'LinearRegression'},{'id': '264', 'type': 'argument_list', 'children': []},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'lm'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'fit'},{'id': '270', 'type': 'argument_list', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'assignment', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'y_new'},{'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '-'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'lm'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '288', 'type': 'return_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'find_next_best'},{'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '295', '296']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'y_new'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'to_be_selected_kmers'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'find_next_best'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304', '305', '306', '307']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'dt_kmer'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '305', 'type': 'list', 'children': [], 'value': '[]'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'nonzero_kmers'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'consider_shift'},{'id': '308', 'type': 'return_statement', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'selected_kmers'}
def best_kmers(dt, response, sequence, k=6, consider_shift=True, n_cores=1, seq_align="start", trim_seq_len=None): y = dt[response] seq = dt[sequence] if trim_seq_len is not None: seq = pad_sequences(seq, align=seq_align, maxlen=trim_seq_len) seq = [s.replace("N", "") for s in seq] dt_kmer = kmer_count(seq, k) Xsp = csc_matrix(dt_kmer) en = ElasticNet(alpha=1, standardize=False, n_splits=3) en.fit(Xsp, y) nonzero_kmers = dt_kmer.columns.values[en.coef_ != 0].tolist() def find_next_best(dt_kmer, y, selected_kmers, to_be_selected_kmers, consider_shift=True): F, pval = f_regression(dt_kmer[to_be_selected_kmers], y) kmer = to_be_selected_kmers.pop(pval.argmin()) selected_kmers.append(kmer) def select_criterion(s1, s2, consider_shift=True): if hamming_distance(s1, s2) <= 1: return False if consider_shift and hamming_distance(s1[1:], s2[:-1]) == 0: return False if consider_shift and hamming_distance(s1[:-1], s2[1:]) == 0: return False return True to_be_selected_kmers = [ckmer for ckmer in to_be_selected_kmers if select_criterion(ckmer, kmer, consider_shift)] if len(to_be_selected_kmers) == 0: return selected_kmers else: lm = LinearRegression() lm.fit(dt_kmer[selected_kmers], y) y_new = y - lm.predict(dt_kmer[selected_kmers]) return find_next_best(dt_kmer, y_new, selected_kmers, to_be_selected_kmers, consider_shift) selected_kmers = find_next_best(dt_kmer, y, [], nonzero_kmers, consider_shift) return selected_kmers
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_custom_rdd_reduce'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'reduce_func'},{'id': '6', 'type': 'block', 'children': ['7', '47', '62']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'accumulating_iter'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '11', 'type': 'block', 'children': ['12', '16', '39']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'iterator'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '24', '29']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '29', 'type': 'else_clause', 'children': ['30']},{'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': 'acc'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'reduce_func'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '39', 'type': 'if_statement', 'children': ['40', '43']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'yield', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'acc'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '50', 'type': 'call', 'children': ['51', '61']},{'id': '51', 'type': 'attribute', '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': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_rdd'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'mapPartitions'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'accumulating_iter'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'collect'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'accumulating_iter'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'vals'}
def _custom_rdd_reduce(self, reduce_func): def accumulating_iter(iterator): acc = None for obj in iterator: if acc is None: acc = obj else: acc = reduce_func(acc, obj) if acc is not None: yield acc vals = self._rdd.mapPartitions(accumulating_iter).collect() return reduce(accumulating_iter, vals)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__sort_analyses'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '5', 'type': 'block', 'children': ['6', '8', '64']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "''' Sorts analysis of all the words in the sentence. \n This is required for consistency, because by default, analyses are \n listed in arbitrary order; '''"},{'id': '8', 'type': 'for_statement', 'children': ['9', '10', '11']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sentence'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16', '27']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'not'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ANALYSIS'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '+'},{'id': '22', 'type': 'string', 'children': [], 'value': "'(!) Error: no analysis found from word: '"},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'ANALYSIS'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40', '41']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'word'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ANALYSIS'},{'id': '40', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'lambda', 'children': ['44', '46']},{'id': '44', 'type': 'lambda_parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'list', 'children': ['52', '55', '58', '61'], 'value': '[x[ROOT],x[POSTAG],x[FORM],x[CLITIC]]'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ROOT'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'POSTAG'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'FORM'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'CLITIC'},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'sentence'}
def __sort_analyses(sentence): ''' Sorts analysis of all the words in the sentence. This is required for consistency, because by default, analyses are listed in arbitrary order; ''' for word in sentence: if ANALYSIS not in word: raise Exception( '(!) Error: no analysis found from word: '+str(word) ) else: word[ANALYSIS] = sorted(word[ANALYSIS], \ key=lambda x : "_".join( [x[ROOT],x[POSTAG],x[FORM],x[CLITIC]] )) return sentence
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tag'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'block', 'children': ['7', '43', '52', '82']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13', '25']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': '=='},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'search_method'},{'id': '12', 'type': 'string', 'children': [], 'value': "'ahocorasick'"},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'events'},{'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': '_find_keywords_ahocorasick'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '25', 'type': 'elif_clause', 'children': ['26', '31']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': '=='},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'search_method'},{'id': '30', 'type': 'string', 'children': [], 'value': "'naive'"},{'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': 'events'},{'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': '_find_keywords_naive'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '_resolve_conflicts'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '65', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '74', 'type': 'slice', 'children': ['75', '78', '79']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '77', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '78', 'type': 'colon', 'children': []},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '81', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '82', 'type': 'if_statement', 'children': ['83', '86', '89']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'return_layer'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '98']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'layer_name'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'events'}
def tag(self, text): if self.search_method == 'ahocorasick': events = self._find_keywords_ahocorasick(text.text) elif self.search_method == 'naive': events = self._find_keywords_naive(text.text) events = self._resolve_conflicts(events) if self.mapping: for item in events: item['type'] = self.map[ text.text[item['start']:item['end']] ] if self.return_layer: return events else: text[self.layer_name] = events
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '8', 'type': 'tuple', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '31', '43', '51', '62', '74', '78', '82', '147', '162', '172']},{'id': '10', 'type': 'if_statement', 'children': ['11', '22']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'tuple', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'search_fields'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'fields'},{'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': 'AttributeError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'concatenated_string', 'children': ['28', '29', '30']},{'id': '28', 'type': 'string', 'children': [], 'value': '"A list of searchable fields must be provided in the class\'s "'},{'id': '29', 'type': 'string', 'children': [], 'value': '"search_fields or provided to this function in the `fields` "'},{'id': '30', 'type': 'string', 'children': [], 'value': '"kwarg."'},{'id': '31', 'type': 'if_statement', 'children': ['32', '34']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'fields'},{'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': 'fields'},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_meta'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'search_fields'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'select'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'like_term'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "''"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'tuple', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '61', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'full_like_term'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "''"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'tuple', 'children': ['71', '72', '73']},{'id': '71', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '73', 'type': 'string', 'children': [], 'value': "'%'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '77', 'type': 'list', 'children': [], 'value': '[]'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'clauses'},{'id': '81', 'type': 'list', 'children': [], 'value': '[]'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '85', 'type': 'block', 'children': ['86', '94', '114']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'clauses'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '110'], 'value': '|'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '106'], 'value': '|'},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '**'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'like_term'},{'id': '110', 'type': '()', 'children': ['111']},{'id': '111', 'type': 'binary_operator', 'children': ['112', '113'], 'value': '**'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'full_like_term'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '146']},{'id': '121', 'type': 'attribute', 'children': ['122', '145']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '142']},{'id': '125', 'type': 'None', 'children': []},{'id': '126', 'type': 'tuple', 'children': ['127', '132', '137']},{'id': '127', 'type': 'tuple', 'children': ['128', '131']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'term'},{'id': '131', 'type': 'integer', 'children': [], 'value': '0'},{'id': '132', 'type': 'tuple', 'children': ['133', '136']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '**'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'like_term'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'tuple', 'children': ['138', '141']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '**'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'full_like_term'},{'id': '141', 'type': 'integer', 'children': [], 'value': '2'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '144', 'type': 'integer', 'children': [], 'value': '3'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '157', 'type': 'argument_list', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'clauses'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'list_splat', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '172', 'type': 'return_statement', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'query'}
def search(cls, term, fields=()): if not any((cls._meta.search_fields, fields)): raise AttributeError( "A list of searchable fields must be provided in the class's " "search_fields or provided to this function in the `fields` " "kwarg." ) if not fields: fields = cls._meta.search_fields query = cls.select() like_term = ''.join((term, '%')) full_like_term = ''.join(('%', term, '%')) order_by = [] clauses = [] for field_name in fields: field = getattr(cls, field_name) clauses.append( (field == term) | (field ** like_term) | (field ** full_like_term) ) order_by.append(case(None, ( (field == term, 0), (field ** like_term, 1), (field ** full_like_term, 2), ), default=3).asc()) query = query.where(reduce(operator.or_, clauses)) query = query.order_by(*order_by) return query
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dependency_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '35']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '25']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_sort_r'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33', '34']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'}
def dependency_sort(dependency_tree): sorted = [] processed = set() for key, deps in dependency_tree.iteritems(): _sort_r(sorted, processed, key, deps, dependency_tree) return sorted
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_r'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'id': '9', 'type': 'block', 'children': ['10', '16', '23', '62']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'in'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dep_key'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '26', 'type': 'block', 'children': ['27', '36', '53']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dep_deps'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dep_key'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dep_deps'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '52']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': '\'"%s" not found, skipped\''},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Repr'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'dep_key'},{'id': '52', 'type': 'continue_statement', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_sort_r'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '60', '61']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'processed'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dep_key'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dep_deps'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dependency_tree'},{'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': 'sorted'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'tuple', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'deps'}
def _sort_r(sorted, processed, key, deps, dependency_tree): if key in processed: return processed.add(key) for dep_key in deps: dep_deps = dependency_tree.get(dep_key) if dep_deps is None: log.debug('"%s" not found, skipped', Repr(dep_key)) continue _sort_r(sorted, processed, dep_key, dep_deps, dependency_tree) sorted.append((key, deps))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '7', 'type': 'integer', 'children': [], 'value': '30'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '10', 'type': 'string', 'children': [], 'value': "'user_ptime'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'show_dir'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '30', '36', '40', '48', '59', '70', '81', '87', '106', '119', '187', '191', '228']},{'id': '21', 'type': 'if_statement', 'children': ['22', '27']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': 'is'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'reload'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '39', 'type': 'dictionary', 'children': []},{'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': 'kwargs'},{'id': '44', 'type': 'string', 'children': [], 'value': "'cid'"},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '52', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '53', 'type': 'conditional_expression', 'children': ['54', '55', '58'], 'value': 'if'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '57', 'type': 'True', 'children': []},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '63', 'type': 'string', 'children': [], 'value': "'show_dir'"},{'id': '64', 'type': 'conditional_expression', 'children': ['65', '66', '69'], 'value': 'if'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'show_dir'},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '74', 'type': 'string', 'children': [], 'value': "'natsort'"},{'id': '75', 'type': 'conditional_expression', 'children': ['76', '77', '80'], 'value': 'if'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '79', 'type': 'True', 'children': []},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '85', 'type': 'string', 'children': [], 'value': "'o'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '87', 'type': 'if_statement', 'children': ['88', '99']},{'id': '88', 'type': 'boolean_operator', 'children': ['89', '92'], 'value': 'or'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'is_root'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '=='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'receiver_directory'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'augmented_assignment', 'children': ['102', '105'], 'value': '+='},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'if_statement', 'children': ['107', '112']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '<='},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '119', 'type': 'try_statement', 'children': ['120', '144']},{'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': 'entries'},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_load_entries'},{'id': '128', 'type': 'argument_list', 'children': ['129', '136', '139', '142']},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_req_files'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'dictionary_splat', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '144', 'type': 'except_clause', 'children': ['145', '149']},{'id': '145', 'type': 'as_pattern', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'RequestFailure'},{'id': '147', 'type': 'as_pattern_target', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'if_statement', 'children': ['151', '158', '183']},{'id': '151', 'type': 'boolean_operator', 'children': ['152', '155'], 'value': 'and'},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '154', 'type': 'True', 'children': []},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '157', 'type': 'string', 'children': [], 'value': "'file_name'"},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162', '163']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '162', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_load_entries'},{'id': '167', 'type': 'argument_list', 'children': ['168', '175', '178', '181']},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '174', 'type': 'identifier', 'children': [], 'value': '_req_aps_natsort_files'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'page'},{'id': '180', 'type': 'integer', 'children': [], 'value': '1'},{'id': '181', 'type': 'dictionary_splat', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '183', 'type': 'else_clause', 'children': ['184']},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'raise_statement', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'for_statement', 'children': ['192', '193', '194']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'if_statement', 'children': ['196', '199', '213']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'in'},{'id': '197', 'type': 'string', 'children': [], 'value': "'pid'"},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': '_instantiate_directory'},{'id': '208', 'type': 'argument_list', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '213', 'type': 'else_clause', 'children': ['214']},{'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': 'res'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_instantiate_file'},{'id': '223', 'type': 'argument_list', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'api'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'res'}
def list(self, count=30, order='user_ptime', asc=False, show_dir=True, natsort=True): if self.cid is None: return False self.reload() kwargs = {} kwargs['cid'] = self.cid kwargs['asc'] = 1 if asc is True else 0 kwargs['show_dir'] = 1 if show_dir is True else 0 kwargs['natsort'] = 1 if natsort is True else 0 kwargs['o'] = order if self.is_root or self == self.api.receiver_directory: self._count += 1 if self.count <= count: count = self.count try: entries = self._load_entries(func=self.api._req_files, count=count, page=1, **kwargs) except RequestFailure as e: if natsort is True and order == 'file_name': entries = \ self._load_entries(func=self.api._req_aps_natsort_files, count=count, page=1, **kwargs) else: raise e res = [] for entry in entries: if 'pid' in entry: res.append(_instantiate_directory(self.api, entry)) else: res.append(_instantiate_file(self.api, entry)) return res
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '25', '40']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '40', 'type': 'return_statement', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'items'}
def list_items(self, sort_key=None, reverse=False): items = list(self.items.values()) if sort_key: items.sort(key=sort_key, reverse=reverse) return items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_axes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '36', '40', '121']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'o_links'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '_overlapping_links'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '22', 'type': 'set_comprehension', 'children': ['23', '24', '27']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ax2'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'o_links'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '39', 'type': 'list', 'children': [], 'value': '[]'},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '53']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '44', 'type': 'argument_list', 'children': ['45', '50']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '53', 'type': 'block', 'children': ['54', '60', '66', '112']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'overlap'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'continue_statement', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'links'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '66', 'type': 'if_statement', 'children': ['67', '70']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'o_links'},{'id': '70', 'type': 'block', 'children': ['71', '84']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '76', 'type': 'expression_list', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '%'},{'id': '88', 'type': 'string', 'children': [], 'value': "'%s%s%s'"},{'id': '89', 'type': 'tuple', 'children': ['90', '91', '111']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '95', 'type': 'generator_expression', 'children': ['96', '103']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '98', 'type': 'slice', 'children': ['99', '100', '101']},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'colon', 'children': []},{'id': '101', 'type': 'unary_operator', 'children': ['102'], 'value': '-'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '108'], 'value': '+'},{'id': '106', 'type': 'list', 'children': ['107'], 'value': '[axis]'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'o_links'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'axes'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'axes'}
def _prepare_axes(node, sort_key): links = node.links o_links = node._overlapping_links overlap = {ax2 for ax in links for ax2 in o_links.get(ax, [])} axes = [] for axis in sorted(links.keys(), key=sort_key): if axis in overlap: continue tgt = links[axis] if axis in o_links: s, e = axis[0], axis[-1] axis = '%s%s%s' % ( s, '&'.join(a[1:-1] for a in [axis] + o_links[axis]), e ) axes.append((axis, tgt)) return axes
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_vid_split'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'vs'},{'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': 'match'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'var_re'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'vs'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19', '33']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'Invalid variable string: {}'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'vs'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '40', 'type': 'argument_list', 'children': []}
def sort_vid_split(vs): match = var_re.match(vs) if match is None: raise ValueError('Invalid variable string: {}'.format(str(vs))) else: return match.groups()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'properties'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '15', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'sortinfo'},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'CVARSORT'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'delete_statement', 'children': ['21']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'CVARSORT'},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'd'}
def properties(self): d = dict(self.sortinfo) if CVARSORT in d: del d[CVARSORT] return d
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_messages_modules'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '5', 'type': 'block', 'children': ['6', '15', '54']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '18', 'type': 'block', 'children': ['19', '28', '37', '45']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'module'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'module_path'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'module_info'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ModuleInfo'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'module_path'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'module_info'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '54', 'type': 'for_statement', 'children': ['55', '58', '63']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'module_messages'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'yield', 'children': ['66']},{'id': '66', 'type': 'tuple', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'module'},{'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': 'module_messages'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '74', 'type': 'lambda', 'children': ['75', '77']},{'id': '75', 'type': 'lambda_parameters', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'line'"}
def build_messages_modules(messages): data = collections.defaultdict(list) for line in messages: module_name = line.get('module') module_path = line.get('path') module_info = ModuleInfo( module_name, module_path, ) data[module_info].append(line) for module, module_messages in data.items(): yield ( module, sorted(module_messages, key=lambda x: x.get('line')))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nml'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nml_path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '40']},{'id': '13', 'type': 'if_statement', 'children': ['14', '26', '34']},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '21'], 'value': 'and'},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nml'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'Namelist'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nml'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'nml_in'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'Namelist'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'nml'},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'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': 'nml_in'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'nml'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'nml_in'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'nml_path'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort'}
def write(nml, nml_path, force=False, sort=False): if not isinstance(nml, Namelist) and isinstance(nml, dict): nml_in = Namelist(nml) else: nml_in = nml nml_in.write(nml_path, force=force, sort=sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'date_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'month_string'},{'id': '6', 'type': 'block', 'children': ['7', '18', '26']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'month_string'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'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': 'month_ord'},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'month_ordinal'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '26', 'type': 'return_statement', 'children': ['27']},{'id': '27', 'type': 'expression_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'month_ord'}
def date_key(cls, month_string): month, year = month_string.split(',') month_ord = cls.month_ordinal[month] return year, month_ord
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'SynchronizedClassMethod'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '28', '50', '176']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '14', '17']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lock_name'},{'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lock_name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '17', 'type': 'if_clause', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lock_name'},{'id': '19', 'type': 'if_statement', 'children': ['20', '22']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'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': '"The lock names list can\'t be empty"'},{'id': '28', 'type': 'if_statement', 'children': ['29', '36']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '33'], 'value': 'or'},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'not'},{'id': '31', 'type': 'string', 'children': [], 'value': '"sorted"'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '35', 'type': 'string', 'children': [], 'value': '"sorted"'},{'id': '36', 'type': 'block', 'children': ['37', '44']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'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': 'locks_attr_names'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '49', 'type': 'argument_list', 'children': []},{'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']},{'id': '51', 'type': 'function_name', 'children': [], 'value': 'wrapped'},{'id': '52', 'type': 'parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '54', 'type': 'block', 'children': ['55', '174']},{'id': '55', 'type': 'decorated_definition', 'children': ['56', '63']},{'id': '56', 'type': 'decorator', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '63', 'type': 'function_definition', 'children': ['64', '65', '71']},{'id': '64', 'type': 'function_name', 'children': [], 'value': 'synchronized'},{'id': '65', 'type': 'parameters', 'children': ['66', '67', '69']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'list_splat_pattern', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '69', 'type': 'dictionary_splat_pattern', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '71', 'type': 'block', 'children': ['72', '84', '92', '96']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'locks'},{'id': '75', 'type': 'list_comprehension', 'children': ['76', '81']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'attr_name'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'try_statement', 'children': ['97', '151']},{'id': '97', 'type': 'block', 'children': ['98', '142']},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '101']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'locks'},{'id': '101', 'type': 'block', 'children': ['102', '125', '129', '135']},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lock'},{'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': 'AttributeError'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"Lock \'{0}\' can\'t be None in class {1}"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '115', 'type': 'argument_list', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'locks_attr_names'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'attribute', 'children': ['120', '124']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'acquire'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'appendleft'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '142', 'type': 'return_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147', '149']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'list_splat', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '149', 'type': 'dictionary_splat', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '151', 'type': 'finally_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153', '163', '169']},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '156', 'type': 'block', 'children': ['157']},{'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': 'lock'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'locked'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '168', 'type': 'argument_list', 'children': []},{'id': '169', 'type': 'delete_statement', 'children': ['170']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'locks'},{'id': '172', 'type': 'slice', 'children': ['173']},{'id': '173', 'type': 'colon', 'children': []},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'synchronized'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'wrapped'}
def SynchronizedClassMethod(*locks_attr_names, **kwargs): locks_attr_names = [ lock_name for lock_name in locks_attr_names if lock_name ] if not locks_attr_names: raise ValueError("The lock names list can't be empty") if "sorted" not in kwargs or kwargs["sorted"]: locks_attr_names = list(locks_attr_names) locks_attr_names.sort() def wrapped(method): @functools.wraps(method) def synchronized(self, *args, **kwargs): locks = [getattr(self, attr_name) for attr_name in locks_attr_names] locked = collections.deque() i = 0 try: for lock in locks: if lock is None: raise AttributeError( "Lock '{0}' can't be None in class {1}".format( locks_attr_names[i], type(self).__name__ ) ) i += 1 lock.acquire() locked.appendleft(lock) return method(self, *args, **kwargs) finally: for lock in locked: lock.release() locked.clear() del locks[:] return synchronized return wrapped
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__sort_registry'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'with_statement', 'children': ['8', '13']},{'id': '8', 'type': 'with_clause', 'children': ['9']},{'id': '9', 'type': 'with_item', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '__svc_lock'},{'id': '13', 'type': 'block', 'children': ['14', '31', '62', '68']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': '__svc_registry'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'BundleException'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"Unknown service: {0}"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '39']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'OBJECTCLASS'},{'id': '39', 'type': 'block', 'children': ['40', '48', '58']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'spec_refs'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '__svc_specs'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'spec_refs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '58', 'type': 'delete_statement', 'children': ['59']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'spec_refs'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'idx'},{'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': 'svc_ref'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'update_sort_key'},{'id': '67', 'type': 'argument_list', 'children': []},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '76']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'svc_ref'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_property'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'OBJECTCLASS'},{'id': '76', 'type': 'block', 'children': ['77', '85']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'spec_refs'},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '__svc_specs'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'bisect'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'insort_left'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'spec_refs'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'svc_ref'}
def __sort_registry(self, svc_ref): with self.__svc_lock: if svc_ref not in self.__svc_registry: raise BundleException("Unknown service: {0}".format(svc_ref)) for spec in svc_ref.get_property(OBJECTCLASS): spec_refs = self.__svc_specs[spec] idx = bisect.bisect_left(spec_refs, svc_ref) del spec_refs[idx] svc_ref.update_sort_key() for spec in svc_ref.get_property(OBJECTCLASS): spec_refs = self.__svc_specs[spec] bisect.insort_left(spec_refs, svc_ref)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_timezones'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '59', '67', '71', '91', '138', '220', '226']},{'id': '5', 'type': 'function_definition', 'children': ['6', '7', '9']},{'id': '6', 'type': 'function_name', 'children': [], 'value': 'hourmin'},{'id': '7', 'type': 'parameters', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '9', 'type': 'block', 'children': ['10', '45', '55']},{'id': '10', 'type': 'if_statement', 'children': ['11', '16', '31']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': '<'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'hours'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '24', 'type': 'argument_list', 'children': ['25', '30']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '-'},{'id': '26', 'type': 'integer', 'children': [], 'value': '86400'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '30', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'hours'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '40', 'type': 'argument_list', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '44', 'type': 'integer', 'children': [], 'value': '3600'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'minutes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '54', 'type': 'integer', 'children': [], 'value': '60'},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'expression_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'hours'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'minutes'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'utcnow'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'timezone_country'},{'id': '70', 'type': 'dictionary', 'children': []},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '76']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'countrycode'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'country_timezones'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '84']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '79', 'type': 'subscript', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'country_timezones'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'countrycode'},{'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': 'timezone_country'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'countrycode'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'timezones'},{'id': '94', 'type': 'list_comprehension', 'children': ['95', '111', '116']},{'id': '95', 'type': 'tuple', 'children': ['96', '110']},{'id': '96', 'type': 'call', 'children': ['97', '105']},{'id': '97', 'type': 'attribute', 'children': ['98', '104']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'utcoffset'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'is_dst'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'common_timezones'},{'id': '116', 'type': 'if_clause', 'children': ['117']},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '133'], 'value': 'and'},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '126'], 'value': 'and'},{'id': '119', 'type': 'not_operator', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': "'US/'"},{'id': '126', 'type': 'not_operator', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'Canada/'"},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'not'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '135', 'type': 'tuple', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'GMT'"},{'id': '137', 'type': 'string', 'children': [], 'value': "'UTC'"},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'presorted'},{'id': '141', 'type': 'list_comprehension', 'children': ['142', '215']},{'id': '142', 'type': 'tuple', 'children': ['143', '144', '214']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '%'},{'id': '145', 'type': 'string', 'children': [], 'value': "'%s%s - %s%s (%s)'"},{'id': '146', 'type': 'tuple', 'children': ['147', '172', '178', '193', '200']},{'id': '147', 'type': 'boolean_operator', 'children': ['148', '171'], 'value': 'or'},{'id': '148', 'type': 'boolean_operator', 'children': ['149', '157'], 'value': 'or'},{'id': '149', 'type': '()', 'children': ['150']},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '156'], 'value': 'and'},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': '<'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '157', 'type': '()', 'children': ['158']},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '170'], 'value': 'and'},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '165'], 'value': 'and'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '=='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '164', 'type': 'integer', 'children': [], 'value': '0'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '=='},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'string', 'children': [], 'value': "' '"},{'id': '171', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'string', 'children': [], 'value': "'%02d:%02d'"},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'hourmin'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '178', 'type': 'conditional_expression', 'children': ['179', '189', '192'], 'value': 'if'},{'id': '179', 'type': '()', 'children': ['180']},{'id': '180', 'type': 'binary_operator', 'children': ['181', '188'], 'value': '+'},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'country_names'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'timezone_country'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '188', 'type': 'string', 'children': [], 'value': "': '"},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'timezone_country'},{'id': '192', 'type': 'string', 'children': [], 'value': "''"},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '199', 'type': 'string', 'children': [], 'value': "' '"},{'id': '200', 'type': 'call', 'children': ['201', '209']},{'id': '201', 'type': 'attribute', 'children': ['202', '208']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'pytz'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'timezone'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'tzname'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'is_dst'},{'id': '213', 'type': 'False', 'children': []},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '215', 'type': 'for_in_clause', 'children': ['216', '219']},{'id': '216', 'type': 'pattern_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'timezones'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'presorted'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'return_statement', 'children': ['227']},{'id': '227', 'type': 'list_comprehension', 'children': ['228', '231']},{'id': '228', 'type': 'tuple', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '231', 'type': 'for_in_clause', 'children': ['232', '236']},{'id': '232', 'type': 'tuple_pattern', 'children': ['233', '234', '235']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'presorted'}
def sorted_timezones(): def hourmin(delta): if delta.days < 0: hours, remaining = divmod(86400 - delta.seconds, 3600) else: hours, remaining = divmod(delta.seconds, 3600) minutes, remaining = divmod(remaining, 60) return hours, minutes now = datetime.utcnow() timezone_country = {} for countrycode in pytz.country_timezones: for timezone in pytz.country_timezones[countrycode]: timezone_country[timezone] = countrycode timezones = [(pytz.timezone(tzname).utcoffset(now, is_dst=False), tzname) for tzname in pytz.common_timezones if not tzname.startswith('US/') and not tzname.startswith('Canada/') and tzname not in ('GMT', 'UTC')] presorted = [(delta, '%s%s - %s%s (%s)' % ( (delta.days < 0 and '-') or (delta.days == 0 and delta.seconds == 0 and ' ') or '+', '%02d:%02d' % hourmin(delta), (pytz.country_names[timezone_country[name]] + ': ') if name in timezone_country else '', name.replace('_', ' '), pytz.timezone(name).tzname(now, is_dst=False)), name) for delta, name in timezones] presorted.sort() return [(name, label) for (delta, label, name) in presorted]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alphanum_order'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'triples'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'triples'},{'id': '11', 'type': 'keyword_argument', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'lambda', 'children': ['14', '16']},{'id': '14', 'type': 'lambda_parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '28']},{'id': '17', 'type': 'conditional_expression', 'children': ['18', '22', '27'], 'value': 'if'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "r'([0-9]+)'"},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'or'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'relation'},{'id': '40', 'type': 'string', 'children': [], 'value': "''"}
def alphanum_order(triples): return sorted( triples, key=lambda t: [ int(t) if t.isdigit() else t for t in re.split(r'([0-9]+)', t.relation or '') ] )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_encode_penman'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '21', '32', '40', '50', '131', '138', '143', '211', '263', '268', '358']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'top'},{'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': 'top'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'triples'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'lambda', 'children': ['47']},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'list', 'children': [], 'value': '[]'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '57']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'triples'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '62', '96']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'inverted'},{'id': '62', 'type': 'block', 'children': ['63', '76']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '74']},{'id': '65', 'type': 'attribute', 'children': ['66', '73']},{'id': '66', 'type': 'subscript', 'children': ['67', '72']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '87']},{'id': '78', 'type': 'attribute', 'children': ['79', '86']},{'id': '79', 'type': 'subscript', 'children': ['80', '85']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Triple'},{'id': '90', 'type': 'argument_list', 'children': ['91', '93']},{'id': '91', 'type': 'list_splat', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'inverted'},{'id': '95', 'type': 'False', 'children': []},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98', '111']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '109']},{'id': '100', 'type': 'attribute', 'children': ['101', '108']},{'id': '101', 'type': 'subscript', 'children': ['102', '107']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '122']},{'id': '113', 'type': 'attribute', 'children': ['114', '121']},{'id': '114', 'type': 'subscript', 'children': ['115', '120']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Triple'},{'id': '125', 'type': 'argument_list', 'children': ['126', '128']},{'id': '126', 'type': 'list_splat', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'inverted'},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'topolist'},{'id': '141', 'type': 'list', 'children': ['142'], 'value': '[top]'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '143', 'type': 'function_definition', 'children': ['144', '145', '147']},{'id': '144', 'type': 'function_name', 'children': [], 'value': '_update'},{'id': '145', 'type': 'parameters', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '147', 'type': 'block', 'children': ['148', '171', '180', '187', '209']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '153', 'type': 'conditional_expression', 'children': ['154', '161', '164'], 'value': 'if'},{'id': '154', 'type': 'tuple', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '157', 'type': 'integer', 'children': [], 'value': '2'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'inverted'},{'id': '164', 'type': 'tuple', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '167', 'type': 'integer', 'children': [], 'value': '0'},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '170', 'type': 'integer', 'children': [], 'value': '2'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '187', 'type': 'if_statement', 'children': ['188', '199']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': '!='},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'relation'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'TYPE_REL'},{'id': '199', 'type': 'block', 'children': ['200', '207']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'topolist'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '207', 'type': 'return_statement', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'None', 'children': []},{'id': '211', 'type': 'function_definition', 'children': ['212', '213', '215']},{'id': '212', 'type': 'function_name', 'children': [], 'value': '_explore_preferred'},{'id': '213', 'type': 'parameters', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '215', 'type': 'block', 'children': ['216', '230', '256']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '219', 'type': 'subscript', 'children': ['220', '229']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '226', 'type': 'tuple', 'children': ['227', '228']},{'id': '227', 'type': 'list', 'children': [], 'value': '[]'},{'id': '228', 'type': 'list', 'children': [], 'value': '[]'},{'id': '229', 'type': 'integer', 'children': [], 'value': '0'},{'id': '230', 'type': 'for_statement', 'children': ['231', '232', '233']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'if_statement', 'children': ['235', '238']},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'in'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '238', 'type': 'block', 'children': ['239', '246']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '246', 'type': 'if_statement', 'children': ['247', '250']},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'is'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '249', 'type': 'None', 'children': []},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': '_explore_preferred'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '262']},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '260', 'type': 'slice', 'children': ['261']},{'id': '261', 'type': 'colon', 'children': []},{'id': '262', 'type': 'list', 'children': [], 'value': '[]'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': '_explore_preferred'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '268', 'type': 'while_statement', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '270', 'type': 'block', 'children': ['271', '289', '308', '328', '341', '348']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'flip_candidates'},{'id': '274', 'type': 'list_comprehension', 'children': ['275', '286']},{'id': '275', 'type': 'subscript', 'children': ['276', '285']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '282', 'type': 'tuple', 'children': ['283', '284']},{'id': '283', 'type': 'list', 'children': [], 'value': '[]'},{'id': '284', 'type': 'list', 'children': [], 'value': '[]'},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'for_in_clause', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'topolist'},{'id': '289', 'type': 'for_statement', 'children': ['290', '291', '292']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'flip_candidates'},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '299']},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '297', 'type': 'slice', 'children': ['298']},{'id': '298', 'type': 'colon', 'children': []},{'id': '299', 'type': 'list_comprehension', 'children': ['300', '301', '304']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '301', 'type': 'for_in_clause', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '304', 'type': 'if_clause', 'children': ['305']},{'id': '305', 'type': 'comparison_operator', 'children': ['306', '307'], 'value': 'in'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'remaining'},{'id': '308', 'type': 'if_statement', 'children': ['309', '322']},{'id': '309', 'type': 'not_operator', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '312', 'type': 'generator_expression', 'children': ['313', '319']},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '318'], 'value': '>'},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '318', 'type': 'integer', 'children': [], 'value': '0'},{'id': '319', 'type': 'for_in_clause', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'flip_candidates'},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'raise_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'EncodeError'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'string', 'children': [], 'value': "'Invalid graph; possibly disconnected.'"},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '333', 'type': 'generator_expression', 'children': ['334', '335', '338']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '335', 'type': 'for_in_clause', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'flip_candidates'},{'id': '338', 'type': 'for_in_clause', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'fc'},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': '_update'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '348', 'type': 'if_statement', 'children': ['349', '352']},{'id': '349', 'type': 'comparison_operator', 'children': ['350', '351'], 'value': 'is'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '351', 'type': 'None', 'children': []},{'id': '352', 'type': 'block', 'children': ['353']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': '_explore_preferred'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'tgt'},{'id': '358', 'type': 'return_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '363']},{'id': '360', 'type': 'attribute', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '362', 'type': 'identifier', 'children': [], 'value': '_layout'},{'id': '363', 'type': 'argument_list', 'children': ['364', '365', '366', '367']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'top'},{'id': '366', 'type': 'integer', 'children': [], 'value': '0'},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '369', 'type': 'argument_list', 'children': []}
def _encode_penman(self, g, top=None): if top is None: top = g.top remaining = set(g.triples()) variables = g.variables() store = defaultdict(lambda: ([], [])) for t in g.triples(): if t.inverted: store[t.target][0].append(t) store[t.source][1].append(Triple(*t, inverted=False)) else: store[t.source][0].append(t) store[t.target][1].append(Triple(*t, inverted=True)) p = defaultdict(list) topolist = [top] def _update(t): src, tgt = (t[2], t[0]) if t.inverted else (t[0], t[2]) p[src].append(t) remaining.remove(t) if tgt in variables and t.relation != self.TYPE_REL: topolist.append(tgt) return tgt return None def _explore_preferred(src): ts = store.get(src, ([], []))[0] for t in ts: if t in remaining: tgt = _update(t) if tgt is not None: _explore_preferred(tgt) ts[:] = [] _explore_preferred(top) while remaining: flip_candidates = [store.get(v, ([],[]))[1] for v in topolist] for fc in flip_candidates: fc[:] = [c for c in fc if c in remaining] if not any(len(fc) > 0 for fc in flip_candidates): raise EncodeError('Invalid graph; possibly disconnected.') c = next(c for fc in flip_candidates for c in fc) tgt = _update(c) if tgt is not None: _explore_preferred(tgt) return self._layout(p, top, 0, set())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13', '18']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_key'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_load'}
def copy(self): return self.__class__(self, key=self._key, load=self._load)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'copy'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '11', 'type': 'argument_list', 'children': ['12', '15', '18']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_key'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_load'},{'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': '_iteritems'},{'id': '22', 'type': 'argument_list', 'children': []}
def copy(self): return self.__class__(self._key, self._load, self._iteritems())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_group'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'return_only_first'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '18', '25', '44']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "''' Sort a dictionary of relative paths and cluster equal paths together at the same time '''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'd_sort'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_dict_of_paths'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '21', 'type': 'tuple', 'children': ['22', '24']},{'id': '22', 'type': 'unary_operator', 'children': ['23'], 'value': '-'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'while_statement', 'children': ['26', '34']},{'id': '26', 'type': '()', 'children': ['27']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '33'], 'value': 'and'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': 'is'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'd_sort'},{'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': 'base_elt'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'd_sort'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'if_statement', 'children': ['45', '50', '53']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'is'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55', '59', '67', '118']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '58', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'lst'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[base_elt]'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '67', 'type': 'if_statement', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'd_sort'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'd_sort'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '80']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': 'is'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'if_statement', 'children': ['82', '89', '100']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '86'], 'value': '=='},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '98']},{'id': '92', 'type': 'attribute', 'children': ['93', '97']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '95', 'type': 'unary_operator', 'children': ['96'], 'value': '-'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102', '106', '114']},{'id': '102', 'type': 'if_statement', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'return_only_first'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'break_statement', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'list', 'children': ['113'], 'value': '[elt]'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'base_elt'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'elt'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'lst'}
def sort_group(d, return_only_first=False): ''' Sort a dictionary of relative paths and cluster equal paths together at the same time ''' d_sort = sort_dict_of_paths(d) base_elt = (-1, None) while (base_elt[1] is None and d_sort): base_elt = d_sort.pop(0) if base_elt[1] is None: return None else: lst = [] lst.append([base_elt]) if d_sort: for elt in d_sort: if elt[1] is not None: if elt[1] == base_elt[1]: lst[-1].append(elt) else: if return_only_first: break lst.append([elt]) base_elt = elt return lst
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_files_by_size_fast'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fileslist'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nbgroups'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1'},{'id': '9', 'type': 'block', 'children': ['10', '12', '18', '22', '26', '45', '50', '302']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': "'''Given a files list with sizes, output a list where the files are grouped in nbgroups per cluster.\n Pseudo-code for algorithm in O(n log(g)) (thank's to insertion sort or binary search trees)\n See for more infos: http://cs.stackexchange.com/questions/44406/fast-algorithm-for-clustering-groups-of-elements-given-their-size-time/44614\n For each file:\n - If to-fill list is empty or file.size > first-key(to-fill):\n * Create cluster c with file in first group g1\n * Add to-fill[file.size].append([c, g2], [c, g3], ..., [c, gn])\n - Else:\n * ksize = first-key(to-fill)\n * c, g = to-fill[ksize].popitem(0)\n * Add file to cluster c in group g\n * nsize = ksize - file.size\n * if nsize > 0:\n . to-fill[nsize].append([c, g])\n . sort to-fill if not an automatic ordering structure\n '''"},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'SortedList'},{'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': 'ftofill_pointer'},{'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': 'fgrouped'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ford'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fileslist'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'lambda', 'children': ['40', '42']},{'id': '40', 'type': 'lambda_parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'while_statement', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ford'},{'id': '52', 'type': 'block', 'children': ['53', '63']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ford'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '73', '228']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '67'], 'value': 'or'},{'id': '65', 'type': 'not_operator', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '>'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '71', 'type': 'unary_operator', 'children': ['72'], 'value': '-'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'block', 'children': ['74', '78', '85', '95']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'augmented_assignment', 'children': ['76', '77'], 'value': '+='},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fgrouped'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'list', 'children': [], 'value': '[]'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'fgrouped'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'list', 'children': ['94'], 'value': '[fname]'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99', '151']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '98', 'type': 'integer', 'children': [], 'value': '0'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '111']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '104', 'type': 'argument_list', 'children': ['105', '108', '109']},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '-'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'nbgroups'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'unary_operator', 'children': ['110'], 'value': '-'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'block', 'children': ['112', '121', '133', '144']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'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': 'fgrouped'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'list', 'children': [], 'value': '[]'},{'id': '121', 'type': 'if_statement', 'children': ['122', '126']},{'id': '122', 'type': 'not_operator', 'children': ['123']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '132', 'type': 'list', 'children': [], 'value': '[]'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'tuple', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'g'},{'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': 'ftofill'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '160']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'xrange'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'nbgroups'},{'id': '160', 'type': 'block', 'children': ['161', '177', '187', '193']},{'id': '161', 'type': 'try_statement', 'children': ['162', '173']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'pattern_list', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'fgname'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'fgsize'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ford'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'except_clause', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'break_statement', 'children': []},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'fgrouped'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'list', 'children': ['186'], 'value': '[fgname]'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'fgname'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '-'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'fgsize'},{'id': '193', 'type': 'if_statement', 'children': ['194', '197']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '>'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'block', 'children': ['198', '210', '221']},{'id': '198', 'type': 'if_statement', 'children': ['199', '203']},{'id': '199', 'type': 'not_operator', 'children': ['200']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'in'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '209']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '209', 'type': 'list', 'children': [], 'value': '[]'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '217']},{'id': '212', 'type': 'attribute', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'tuple', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'last_cid'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'diff_size'},{'id': '228', 'type': 'else_clause', 'children': ['229']},{'id': '229', 'type': 'block', 'children': ['230', '238', '250', '261', '267']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'ksize'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '243']},{'id': '240', 'type': 'pattern_list', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '243', 'type': 'call', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'ksize'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '249', 'type': 'argument_list', 'children': []},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '259']},{'id': '252', 'type': 'attribute', 'children': ['253', '258']},{'id': '253', 'type': 'subscript', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'fgrouped'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '-'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'ksize'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'fsize'},{'id': '267', 'type': 'if_statement', 'children': ['268', '271']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': '>'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '270', 'type': 'integer', 'children': [], 'value': '0'},{'id': '271', 'type': 'block', 'children': ['272', '284', '295']},{'id': '272', 'type': 'if_statement', 'children': ['273', '277']},{'id': '273', 'type': 'not_operator', 'children': ['274']},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': 'in'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '283']},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '283', 'type': 'list', 'children': [], 'value': '[]'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '291']},{'id': '286', 'type': 'attribute', 'children': ['287', '290']},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ftofill_pointer'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'tuple', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ftofill'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'nsize'},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'fgrouped'}
def group_files_by_size_fast(fileslist, nbgroups, mode=1): '''Given a files list with sizes, output a list where the files are grouped in nbgroups per cluster. Pseudo-code for algorithm in O(n log(g)) (thank's to insertion sort or binary search trees) See for more infos: http://cs.stackexchange.com/questions/44406/fast-algorithm-for-clustering-groups-of-elements-given-their-size-time/44614 For each file: - If to-fill list is empty or file.size > first-key(to-fill): * Create cluster c with file in first group g1 * Add to-fill[file.size].append([c, g2], [c, g3], ..., [c, gn]) - Else: * ksize = first-key(to-fill) * c, g = to-fill[ksize].popitem(0) * Add file to cluster c in group g * nsize = ksize - file.size * if nsize > 0: . to-fill[nsize].append([c, g]) . sort to-fill if not an automatic ordering structure ''' ftofill = SortedList() ftofill_pointer = {} fgrouped = [] ford = sorted(fileslist.iteritems(), key=lambda x: x[1]) last_cid = -1 while ford: fname, fsize = ford.pop() if not ftofill or fsize > ftofill[-1]: last_cid += 1 fgrouped.append([]) fgrouped[last_cid].append([fname]) if mode==0: for g in xrange(nbgroups-1, 0, -1): fgrouped[last_cid].append([]) if not fsize in ftofill_pointer: ftofill_pointer[fsize] = [] ftofill_pointer[fsize].append((last_cid, g)) ftofill.add(fsize) else: for g in xrange(1, nbgroups): try: fgname, fgsize = ford.pop() except IndexError: break fgrouped[last_cid].append([fgname]) diff_size = fsize - fgsize if diff_size > 0: if not diff_size in ftofill_pointer: ftofill_pointer[diff_size] = [] ftofill_pointer[diff_size].append((last_cid, g)) ftofill.add(diff_size) else: ksize = ftofill.pop() c, g = ftofill_pointer[ksize].pop() fgrouped[c][g].append(fname) nsize = ksize - fsize if nsize > 0: if not nsize in ftofill_pointer: ftofill_pointer[nsize] = [] ftofill_pointer[nsize].append((c, g)) ftofill.add(nsize) return fgrouped
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '15'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '13', 'type': 'string', 'children': [], 'value': "'descending'"},{'id': '14', 'type': 'block', 'children': ['15', '19', '33', '55', '61', '76', '186', '195', '212', '218']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36', '43', '45']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '36', 'type': 'ERROR', 'children': ['37', '38', '40']},{'id': '37', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '38', 'type': 'ERROR', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'if'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'not'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '43', 'type': 'ERROR', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'raise'},{'id': '45', 'type': 'type', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'string', 'children': [], 'value': '"invalid sort, should be one of"'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '58', 'type': 'list', 'children': ['59', '60'], 'value': "['ascending', 'descending']"},{'id': '59', 'type': 'string', 'children': [], 'value': "'ascending'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'descending'"},{'id': '61', 'type': 'if_statement', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'not'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'},{'id': '71', 'type': 'string', 'children': [], 'value': '"invalid order, should be one of"'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'orders'},{'id': '76', 'type': 'if_statement', 'children': ['77', '85', '133']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '84'], 'value': '=='},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'if_statement', 'children': ['87', '90', '108']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '89', 'type': 'string', 'children': [], 'value': '"ascending"'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'lambda', 'children': ['100', '102']},{'id': '100', 'type': 'lambda_parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_repr'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'elif_clause', 'children': ['109', '112']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '111', 'type': 'string', 'children': [], 'value': '"descending"'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '118', 'type': 'argument_list', 'children': ['119', '130']},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '121', 'type': 'lambda', 'children': ['122', '124']},{'id': '122', 'type': 'lambda_parameters', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_repr'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '132', 'type': 'True', 'children': []},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '139', '159']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '=='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '138', 'type': 'string', 'children': [], 'value': '"ascending"'},{'id': '139', 'type': 'block', 'children': ['140']},{'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': 'localrows'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '148', 'type': 'lambda', 'children': ['149', '151']},{'id': '149', 'type': 'lambda_parameters', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '159', 'type': 'elif_clause', 'children': ['160', '163']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '162', 'type': 'string', 'children': [], 'value': '"descending"'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '169', 'type': 'argument_list', 'children': ['170', '183']},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '172', 'type': 'lambda', 'children': ['173', '175']},{'id': '173', 'type': 'lambda_parameters', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '185', 'type': 'True', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '191', 'type': 'slice', 'children': ['192', '193', '194']},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'colon', 'children': []},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '203', 'type': 'integer', 'children': [], 'value': '2'},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'stringutils'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'pp'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '211', 'type': 'integer', 'children': [], 'value': '2'},{'id': '212', 'type': 'ERROR', 'children': ['213', '216', '217']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'localrows'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '216', 'type': 'integer', 'children': [], 'value': '0'},{'id': '217', 'type': 'string', 'children': [], 'value': '"types"'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_print_table'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'localrows'}
def print_(rows, limit=15, sort='size', order='descending'): localrows = [] for row in rows: localrows.append(list(row)) sortby = ['type', ' if sort not in sortby: raise ValueError("invalid sort, should be one of" + str(sortby)) orders = ['ascending', 'descending'] if order not in orders: raise ValueError("invalid order, should be one of" + str(orders)) if sortby.index(sort) == 0: if order == "ascending": localrows.sort(key=lambda x: _repr(x[0])) elif order == "descending": localrows.sort(key=lambda x: _repr(x[0]), reverse=True) else: if order == "ascending": localrows.sort(key=lambda x: x[sortby.index(sort)]) elif order == "descending": localrows.sort(key=lambda x: x[sortby.index(sort)], reverse=True) localrows = localrows[0:limit] for row in localrows: row[2] = stringutils.pp(row[2]) localrows.insert(0,["types", " _print_table(localrows)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_and_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '17', '35', '50']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '16', 'type': 'argument_list', 'children': []},{'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': 'graphs'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'lambda', 'children': ['26', '28']},{'id': '26', 'type': 'lambda_parameters', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '35', 'type': 'for_statement', 'children': ['36', '39', '43']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'graphs'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'graphs'}
def split_and_sort(self): graphs = list(self.split()) graphs.sort(key=lambda x: -len(x.metadata)) for index, graph in enumerate(graphs): graph.index = index return graphs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'profile'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '9', 'type': 'integer', 'children': [], 'value': '0'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'immediate'},{'id': '15', 'type': 'False', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '24', 'type': 'integer', 'children': [], 'value': '40'},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '27', 'type': 'tuple', 'children': ['28', '29', '30']},{'id': '28', 'type': 'string', 'children': [], 'value': "'cProfile'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '30', 'type': 'string', 'children': [], 'value': "'hotshot'"},{'id': '31', 'type': 'block', 'children': ['32', '70', '82', '112', '137', '153', '161', '169', '177', '185']},{'id': '32', 'type': 'if_statement', 'children': ['33', '36']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'block', 'children': ['37', '68']},{'id': '37', 'type': 'function_definition', 'children': ['38', '39', '41']},{'id': '38', 'type': 'function_name', 'children': [], 'value': 'decorator'},{'id': '39', 'type': 'parameters', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'fn'},{'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': 'profile'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47', '50', '53', '56', '59', '62', '65']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'immediate'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'immediate'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'decorator'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '80', 'type': 'list', 'children': ['81'], 'value': '[profiler]'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85', '98']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'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': 'p'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'AVAILABLE_PROFILERS'},{'id': '90', 'type': 'block', 'children': ['91', '97']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'profiler_class'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'AVAILABLE_PROFILERS'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '97', 'type': 'break_statement', 'children': []},{'id': '98', 'type': 'else_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': "'only these profilers are available: %s'"},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "', '"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'AVAILABLE_PROFILERS'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'profiler_class'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119', '122', '125', '128', '131', '134']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'immediate'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'immediate'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '137', 'type': 'function_definition', 'children': ['138', '139', '144']},{'id': '138', 'type': 'function_name', 'children': [], 'value': 'new_fn'},{'id': '139', 'type': 'parameters', 'children': ['140', '142']},{'id': '140', 'type': 'list_splat_pattern', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '142', 'type': 'dictionary_splat_pattern', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '148', 'type': 'argument_list', 'children': ['149', '151']},{'id': '149', 'type': 'list_splat', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '151', 'type': 'dictionary_splat', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'kw'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'new_fn'},{'id': '157', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'new_fn'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'new_fn'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'new_fn'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fn'},{'id': '184', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'new_fn'}
def profile(fn=None, skip=0, filename=None, immediate=False, dirs=False, sort=None, entries=40, profiler=('cProfile', 'profile', 'hotshot')): if fn is None: def decorator(fn): return profile(fn, skip=skip, filename=filename, immediate=immediate, dirs=dirs, sort=sort, entries=entries, profiler=profiler) return decorator if isinstance(profiler, str): profiler = [profiler] for p in profiler: if p in AVAILABLE_PROFILERS: profiler_class = AVAILABLE_PROFILERS[p] break else: raise ValueError('only these profilers are available: %s' % ', '.join(AVAILABLE_PROFILERS)) fp = profiler_class(fn, skip=skip, filename=filename, immediate=immediate, dirs=dirs, sort=sort, entries=entries) def new_fn(*args, **kw): return fp(*args, **kw) new_fn.__doc__ = fn.__doc__ new_fn.__name__ = fn.__name__ new_fn.__dict__ = fn.__dict__ new_fn.__module__ = fn.__module__ return new_fn
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_kernel_arguments'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '36']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '21']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': '_kernel_data'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'declarations'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_kernel_parameters'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'},{'id': '34', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'declarations'}
def _get_kernel_arguments(self): declarations = [] for name, data in self._kernel_data.items(): declarations.extend(data.get_kernel_parameters('_' + name)) return declarations
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '36', '58', '87', '114', '215', '220', '229', '236', '241', '245', '278']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'check_self_dependencies'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'for_statement', 'children': ['12', '15', '20']},{'id': '12', 'type': 'pattern_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'Self-dependency, {} depends on itself.'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '36', 'type': 'function_definition', 'children': ['37', '38', '40']},{'id': '37', 'type': 'function_name', 'children': [], 'value': 'prepare_input_data'},{'id': '38', 'type': 'parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'dictionary_comprehension', 'children': ['43', '49']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'for_in_clause', 'children': ['50', '53']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'function_definition', 'children': ['59', '60', '62']},{'id': '59', 'type': 'function_name', 'children': [], 'value': 'find_items_without_dependencies'},{'id': '60', 'type': 'parameters', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'return_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '79'], 'value': '-'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'function_definition', 'children': ['88', '89', '91']},{'id': '88', 'type': 'function_name', 'children': [], 'value': 'add_empty_dependencies'},{'id': '89', 'type': 'parameters', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '91', 'type': 'block', 'children': ['92', '99']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'items_without_dependencies'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'find_items_without_dependencies'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'dictionary_comprehension', 'children': ['106', '111']},{'id': '106', 'type': 'pair', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'items_without_dependencies'},{'id': '114', 'type': 'function_definition', 'children': ['115', '116', '118']},{'id': '115', 'type': 'function_name', 'children': [], 'value': 'get_sorted'},{'id': '116', 'type': 'parameters', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '118', 'type': 'block', 'children': ['119', '123', '180']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'input_data'},{'id': '123', 'type': 'while_statement', 'children': ['124', '125']},{'id': '124', 'type': 'True', 'children': []},{'id': '125', 'type': 'block', 'children': ['126', '149', '154', '157']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '131', 'type': 'generator_expression', 'children': ['132', '133', '142']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '133', 'type': 'for_in_clause', 'children': ['134', '137']},{'id': '134', 'type': 'pattern_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'if_clause', 'children': ['143']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': '=='},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'if_statement', 'children': ['150', '152']},{'id': '150', 'type': 'not_operator', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'break_statement', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'yield', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '160', 'type': 'dictionary_comprehension', 'children': ['161', '167', '176']},{'id': '161', 'type': 'pair', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '-'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '171']},{'id': '168', 'type': 'pattern_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'if_clause', 'children': ['177']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'not'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '180', 'type': 'if_statement', 'children': ['181', '187']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '186'], 'value': '!='},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '186', 'type': 'integer', 'children': [], 'value': '0'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'raise_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '198']},{'id': '193', 'type': 'attribute', 'children': ['194', '197']},{'id': '194', 'type': 'concatenated_string', 'children': ['195', '196']},{'id': '195', 'type': 'string', 'children': [], 'value': "'Cyclic dependencies exist '"},{'id': '196', 'type': 'string', 'children': [], 'value': "'among these items: {}'"},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "', '"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '203', 'type': 'generator_expression', 'children': ['204', '208']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'check_self_dependencies'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '220', 'type': 'if_statement', 'children': ['221', '226']},{'id': '221', 'type': 'not_operator', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'list', 'children': [], 'value': '[]'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'data_copy'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'prepare_input_data'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'add_empty_dependencies'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'data_copy'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '244', 'type': 'list', 'children': [], 'value': '[]'},{'id': '245', 'type': 'for_statement', 'children': ['246', '247', '251']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'get_sorted'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'data_copy'},{'id': '251', 'type': 'block', 'children': ['252', '271']},{'id': '252', 'type': 'try_statement', 'children': ['253', '261']},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '261', 'type': 'except_clause', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '278', 'type': 'return_statement', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'result'}
def topological_sort(data): def check_self_dependencies(input_data): for k, v in input_data.items(): if k in v: raise ValueError('Self-dependency, {} depends on itself.'.format(k)) def prepare_input_data(input_data): return {k: set(v) for k, v in input_data.items()} def find_items_without_dependencies(input_data): return list(reduce(set.union, input_data.values()) - set(input_data.keys())) def add_empty_dependencies(data): items_without_dependencies = find_items_without_dependencies(data) data.update({item: set() for item in items_without_dependencies}) def get_sorted(input_data): data = input_data while True: ordered = set(item for item, dep in data.items() if len(dep) == 0) if not ordered: break yield ordered data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered} if len(data) != 0: raise ValueError('Cyclic dependencies exist ' 'among these items: {}'.format(', '.join(repr(x) for x in data.items()))) check_self_dependencies(data) if not len(data): return [] data_copy = prepare_input_data(data) add_empty_dependencies(data_copy) result = [] for d in get_sorted(data_copy): try: d = sorted(d) except TypeError: d = list(d) result.extend(d) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_posts'},{'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': 'include_draft'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter_functions'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '136', '150', '169', '179']},{'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']},{'id': '13', 'type': 'function_name', 'children': [], 'value': 'posts_generator'},{'id': '14', 'type': 'parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'if_statement', 'children': ['18', '26']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'for_statement', 'children': ['28', '29', '35']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '35', 'type': 'block', 'children': ['36', '49', '60']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'format_name'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_standard_format_name'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '57', 'type': 'slice', 'children': ['58', '59']},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'colon', 'children': []},{'id': '60', 'type': 'if_statement', 'children': ['61', '72']},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'and'},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format_name'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "r'\\d{4}-\\d{2}-\\d{2}-.+'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '72', 'type': 'block', 'children': ['73', '79', '85', '108', '123', '133']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Post'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'format_name'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '94']},{'id': '87', 'type': 'pattern_list', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'raw_content'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'FileStorage'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rel_url'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '122'], 'value': '+'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']},{'id': '119', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '120', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '121', 'type': 'integer', 'children': [], 'value': '3'},{'id': '122', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'unique_key'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'},{'id': '129', 'type': 'string', 'children': [], 'value': "'/post/'"},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'rel_url'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'yield', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'posts_path'},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'current_app'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'instance_path'},{'id': '149', 'type': 'string', 'children': [], 'value': "'posts'"},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '155', 'type': 'argument_list', 'children': ['156', '165']},{'id': '156', 'type': 'lambda', 'children': ['157', '159']},{'id': '157', 'type': 'lambda_parameters', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '161'], 'value': 'or'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'include_draft'},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'is_draft'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'posts_generator'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'posts_path'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_filter_result'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'filter_functions'},{'id': '179', 'type': 'return_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184', '192']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '186', 'type': 'lambda', 'children': ['187', '189']},{'id': '187', 'type': 'lambda_parameters', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '194', 'type': 'True', 'children': []}
def get_posts(self, include_draft=False, filter_functions=None): def posts_generator(path): if os.path.isdir(path): for file in os.listdir(path): filename, ext = os.path.splitext(file) format_name = get_standard_format_name(ext[1:]) if format_name is not None and re.match( r'\d{4}-\d{2}-\d{2}-.+', filename): post = Post() post.format = format_name post.meta, post.raw_content = FileStorage.read_file( os.path.join(path, file)) post.rel_url = filename.replace('-', '/', 3) + '/' post.unique_key = '/post/' + post.rel_url yield post posts_path = os.path.join(current_app.instance_path, 'posts') result = filter(lambda p: include_draft or not p.is_draft, posts_generator(posts_path)) result = self._filter_result(result, filter_functions) return sorted(result, key=lambda p: p.created, reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'arbitrary_object_to_string'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '5', 'type': 'block', 'children': ['6', '13', '24', '50', '65', '81', '93', '159', '169']},{'id': '6', 'type': 'if_statement', 'children': ['7', '10']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "''"},{'id': '13', 'type': 'if_statement', 'children': ['14', '21']},{'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': 'a_thing'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '24', 'type': 'if_statement', 'children': ['25', '36']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'PY3'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'binary_type'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'try_statement', 'children': ['38', '46']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '46', 'type': 'except_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'pass_statement', 'children': []},{'id': '50', 'type': 'try_statement', 'children': ['51', '58']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'to_str'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'except_clause', 'children': ['59', '63']},{'id': '59', 'type': 'tuple', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'pass_statement', 'children': []},{'id': '65', 'type': 'try_statement', 'children': ['66', '74']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'arbitrary_object_to_string'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'a_type'},{'id': '74', 'type': 'except_clause', 'children': ['75', '79']},{'id': '75', 'type': 'tuple', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'pass_statement', 'children': []},{'id': '81', 'type': 'try_statement', 'children': ['82', '87']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'known_mapping_type_to_str'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '87', 'type': 'except_clause', 'children': ['88', '91']},{'id': '88', 'type': 'tuple', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'pass_statement', 'children': []},{'id': '93', 'type': 'try_statement', 'children': ['94', '155']},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': 'not'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '99', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '100', 'type': 'tuple', 'children': ['101', '102', '103']},{'id': '101', 'type': 'string', 'children': [], 'value': "'__builtin__'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'builtins'"},{'id': '103', 'type': 'string', 'children': [], 'value': "'exceptions'"},{'id': '104', 'type': 'block', 'children': ['105', '147']},{'id': '105', 'type': 'if_statement', 'children': ['106', '111', '139']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '=='},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '110', 'type': 'string', 'children': [], 'value': '"__main__"'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '137']},{'id': '117', 'type': 'attribute', 'children': ['118', '136']},{'id': '118', 'type': 'call', 'children': ['119', '133']},{'id': '119', 'type': 'attribute', 'children': ['120', '132']},{'id': '120', 'type': 'subscript', 'children': ['121', '128']},{'id': '121', 'type': 'attribute', 'children': ['122', '127']},{'id': '122', 'type': 'subscript', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '126', 'type': 'string', 'children': [], 'value': "'__main__'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': '__file__'},{'id': '128', 'type': 'slice', 'children': ['129', '130']},{'id': '129', 'type': 'colon', 'children': []},{'id': '130', 'type': 'unary_operator', 'children': ['131'], 'value': '-'},{'id': '131', 'type': 'integer', 'children': [], 'value': '3'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '135', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '%'},{'id': '149', 'type': 'string', 'children': [], 'value': '"%s.%s"'},{'id': '150', 'type': 'tuple', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'module_name'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '154', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '155', 'type': 'except_clause', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'pass_statement', 'children': []},{'id': '159', 'type': 'try_statement', 'children': ['160', '165']},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'return_statement', 'children': ['162']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'a_thing'},{'id': '164', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '165', 'type': 'except_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'pass_statement', 'children': []},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'a_thing'}
def arbitrary_object_to_string(a_thing): if a_thing is None: return '' if isinstance(a_thing, six.string_types): return a_thing if six.PY3 and isinstance(a_thing, six.binary_type): try: return a_thing.decode('utf-8') except UnicodeDecodeError: pass try: return a_thing.to_str() except (AttributeError, KeyError, TypeError): pass try: return arbitrary_object_to_string(a_thing.a_type) except (AttributeError, KeyError, TypeError): pass try: return known_mapping_type_to_str[a_thing] except (KeyError, TypeError): pass try: if a_thing.__module__ not in ('__builtin__', 'builtins', 'exceptions'): if a_thing.__module__ == "__main__": module_name = ( sys.modules['__main__'] .__file__[:-3] .replace('/', '.') .strip('.') ) else: module_name = a_thing.__module__ return "%s.%s" % (module_name, a_thing.__name__) except AttributeError: pass try: return a_thing.__name__ except AttributeError: pass return str(a_thing)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_parser'},{'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', '16', '24', '32', '38', '50', '66', '84']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'command_name'},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'},{'id': '28', 'type': 'string', 'children': [], 'value': "'configman_subparsers_option'"},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_configman_option'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'},{'id': '36', 'type': 'string', 'children': [], 'value': "'subparser_name'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'command_name'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'subparsers'},{'id': '41', 'type': 'attribute', 'children': ['42', '49']},{'id': '42', 'type': 'attribute', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_configman_option'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'foreign_data'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'subparsers'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'a_subparser'},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ConfigmanSubParsersAction'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'add_parser'},{'id': '61', 'type': 'argument_list', 'children': ['62', '64']},{'id': '62', 'type': 'list_splat', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '64', 'type': 'dictionary_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'subparsers'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'command_name'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'DotDict'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'dictionary', 'children': ['75', '78', '81']},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"args"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '78', 'type': 'pair', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"kwargs"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'},{'id': '81', 'type': 'pair', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': '"subparser"'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'a_subparser'},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'a_subparser'}
def add_parser(self, *args, **kwargs): command_name = args[0] new_kwargs = kwargs.copy() new_kwargs['configman_subparsers_option'] = self._configman_option new_kwargs['subparser_name'] = command_name subparsers = self._configman_option.foreign_data.argparse.subparsers a_subparser = super(ConfigmanSubParsersAction, self).add_parser( *args, **new_kwargs ) subparsers[command_name] = DotDict({ "args": args, "kwargs": new_kwargs, "subparser": a_subparser }) return a_subparser
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_and_sort_accept_header'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'accept_header'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '9', 'type': 'argument_list', 'children': ['10', '23', '31']},{'id': '10', 'type': 'list_comprehension', 'children': ['11', '15']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_split_into_mimetype_and_priority'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'for_in_clause', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'accept_header'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "','"},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'lambda', 'children': ['26', '28']},{'id': '26', 'type': 'lambda_parameters', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '33', 'type': 'True', 'children': []}
def _parse_and_sort_accept_header(accept_header): return sorted([_split_into_mimetype_and_priority(x) for x in accept_header.split(',')], key=lambda x: x[1], reverse=True)