sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize_to_normalized_pretty_json'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'py_obj'}, {'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': 'json'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13', '16', '19']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'py_obj'}, {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ToJsonCompatibleTypes'}
def serialize_to_normalized_pretty_json(py_obj): return json.dumps(py_obj, sort_keys=True, indent=2, cls=ToJsonCompatibleTypes)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize_to_normalized_compact_json'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'py_obj'}, {'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': 'json'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dumps'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13', '16', '21']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'py_obj'}, {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'separators'}; {'id': '18', 'type': 'tuple', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "','"}; {'id': '20', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ToJsonCompatibleTypes'}
def serialize_to_normalized_compact_json(py_obj): return json.dumps( py_obj, sort_keys=True, separators=(',', ':'), cls=ToJsonCompatibleTypes )
{'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': 'unsorted_dict'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '16', '20', '28', '79']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}, {'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': 'sorted_set'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'unconnected_dict'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'unsorted_dict'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'while_statement', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '30', 'type': 'block', 'children': ['31', '35']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'for_statement', 'children': ['36', '39', '47']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'obsoletes_pid'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'unconnected_dict'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '56']}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'or'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'obsoletes_pid'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'in'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'obsoletes_pid'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted_set'}; {'id': '56', 'type': 'block', 'children': ['57', '61', '68', '75']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '60', 'type': 'True', 'children': []}, {'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': 'sorted_list'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pid'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted_set'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '75', 'type': 'delete_statement', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'unconnected_dict'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'expression_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}
def topological_sort(unsorted_dict): sorted_list = [] sorted_set = set() found = True unconnected_dict = unsorted_dict.copy() while found: found = False for pid, obsoletes_pid in list(unconnected_dict.items()): if obsoletes_pid is None or obsoletes_pid in sorted_set: found = True sorted_list.append(pid) sorted_set.add(pid) del unconnected_dict[pid] return sorted_list, unconnected_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_elements_by_child_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj_pyxb'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'child_name_list'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'obj_pyxb'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'lambda', 'children': ['16', '18']}; {'id': '16', 'type': 'lambda_parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '18', 'type': 'list_comprehension', 'children': ['19', '27']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_auto'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'child_name_list'}
def sort_elements_by_child_values(obj_pyxb, child_name_list): obj_pyxb.sort(key=lambda x: [get_auto(getattr(x, n)) for n in child_name_list])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_field_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'maxvalues'}; {'id': '8', 'type': 'unary_operator', 'children': ['9'], 'value': '-'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '12', 'type': 'True', 'children': []}, {'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'query_dict'}, {'id': '15', 'type': 'block', 'children': ['16', '24', '59', '69', '77', '87']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'param_dict'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'query_dict'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'param_dict'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'dictionary', 'children': ['31', '34', '37', '40', '46', '49']}, {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'rows'"}, {'id': '33', 'type': 'string', 'children': [], 'value': "'0'"}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'facet'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'true'"}, {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'facet.field'"}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'facet.limit'"}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'maxvalues'}; {'id': '46', 'type': 'pair', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': "'facet.zeros'"}; {'id': '48', 'type': 'string', 'children': [], 'value': "'false'"}, {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'facet.sort'"}, {'id': '51', 'type': 'call', 'children': ['52', '58']}; {'id': '52', 'type': 'attribute', 'children': ['53', '57']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'resp_dict'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_post_query'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'dictionary_splat', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'param_dict'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'result_dict'}; {'id': '72', 'type': 'subscript', 'children': ['73', '76']}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'resp_dict'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'facet_counts'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'facet_fields'"}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'result_dict'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'numFound'"}; {'id': '82', 'type': 'subscript', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'resp_dict'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'response'"}; {'id': '86', 'type': 'string', 'children': [], 'value': "'numFound'"}, {'id': '87', 'type': 'return_statement', 'children': ['88']}
def get_field_values(self, name, maxvalues=-1, sort=True, **query_dict): param_dict = query_dict.copy() param_dict.update( { 'rows': '0', 'facet': 'true', 'facet.field': name, 'facet.limit': str(maxvalues), 'facet.zeros': 'false', 'facet.sort': str(sort).lower(), } ) resp_dict = self._post_query(**param_dict) result_dict = resp_dict['facet_counts']['facet_fields'] result_dict['numFound'] = resp_dict['response']['numFound'] return result_dict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bin'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'maxX'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'minX'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '15', '28', '41', '65']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'''\n bin signal x using 'binsN' bin. If minX, maxX are None, they default to the full\n range of the signal. If they are not None, everything above maxX gets assigned to\n binsN-1 and everything below minX gets assigned to 0, this is effectively the same\n as clipping x before passing it to 'bin'\n input:\n -----\n x: signal to be binned, some sort of iterable\n bins: int, number of bins\n iterable, bin edges\n maxX: clips data above maxX\n minX: clips data below maxX\n output:\n ------\n binnedX: x after being binned\n bins: bins used for binning.\n if input 'bins' is already an iterable it just returns the\n same iterable\n example:\n bin(x, 10)\n entropy)\n binsN = 10\n percentiles = list(np.arange(0, 100.1, 100/binsN))\n bins = np.percentile(x, percentiles)\n bin(x, bins)\n '''"}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'maxX'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'maxX'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'minX'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'minX'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'not_operator', 'children': ['43']}, {'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': 'iterable'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bins'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bins'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'linspace'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '62']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'minX'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'maxX'}, {'id': '61', 'type': 'float', 'children': [], 'value': '1e-5'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'expression_list', 'children': ['67', '85']}, {'id': '67', 'type': 'call', 'children': ['68', '81']}; {'id': '68', 'type': 'attribute', 'children': ['69', '80']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'digitize'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '79']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ravel'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'bins'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bins'}
def bin(x, bins, maxX=None, minX=None): ''' bin signal x using 'binsN' bin. If minX, maxX are None, they default to the full range of the signal. If they are not None, everything above maxX gets assigned to binsN-1 and everything below minX gets assigned to 0, this is effectively the same as clipping x before passing it to 'bin' input: ----- x: signal to be binned, some sort of iterable bins: int, number of bins iterable, bin edges maxX: clips data above maxX minX: clips data below maxX output: ------ binnedX: x after being binned bins: bins used for binning. if input 'bins' is already an iterable it just returns the same iterable example: bin(x, 10) entropy) binsN = 10 percentiles = list(np.arange(0, 100.1, 100/binsN)) bins = np.percentile(x, percentiles) bin(x, bins) ''' if maxX is None: maxX = x.max() if minX is None: minX = x.min() if not np.iterable(bins): bins = np.linspace(minX, maxX+1e-5, bins+1) return np.digitize(x.ravel(), bins).reshape(x.shape), bins
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_item'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'table_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key_dict'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'condition_expression'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'update_expression'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'return_values'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '47', '56', '65', '80', '94', '109', '123']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '32', 'type': 'dictionary', 'children': ['33', '36', '44']}, {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'TableName'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'table_name'}; {'id': '36', 'type': 'pair', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'Key'"}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'marshall'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key_dict'}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'UpdateExpression'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'update_expression'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'condition_expression'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'ConditionExpression'"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'condition_expression'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'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': 'payload'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeNames'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '73', '74']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeValues'"}, {'id': '73', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'marshall'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}; {'id': '82', 'type': 'block', 'children': ['83', '88']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_validate_return_consumed_capacity'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'ReturnConsumedCapacity'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'}; {'id': '96', 'type': 'block', 'children': ['97', '102']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_validate_return_item_collection_metrics'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107', '108']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'ReturnItemCollectionMetrics'"}, {'id': '107', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'return_values'}, {'id': '111', 'type': 'block', 'children': ['112', '117']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_validate_return_values'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'return_values'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'ReturnValues'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'return_values'}, {'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': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'UpdateItem'"}
def update_item(self, table_name, key_dict, condition_expression=None, update_expression=None, expression_attribute_names=None, expression_attribute_values=None, return_consumed_capacity=None, return_item_collection_metrics=None, return_values=None): payload = {'TableName': table_name, 'Key': utils.marshall(key_dict), 'UpdateExpression': update_expression} if condition_expression: payload['ConditionExpression'] = condition_expression if expression_attribute_names: payload['ExpressionAttributeNames'] = expression_attribute_names if expression_attribute_values: payload['ExpressionAttributeValues'] = \ utils.marshall(expression_attribute_values) if return_consumed_capacity: _validate_return_consumed_capacity(return_consumed_capacity) payload['ReturnConsumedCapacity'] = return_consumed_capacity if return_item_collection_metrics: _validate_return_item_collection_metrics( return_item_collection_metrics) payload['ReturnItemCollectionMetrics'] = \ return_item_collection_metrics if return_values: _validate_return_values(return_values) payload['ReturnValues'] = return_values return self.execute('UpdateItem', payload)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '42']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36', '39']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'table_name'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'index_name'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'consistent_read'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key_condition_expression'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filter_expression'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'projection_expression'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'select'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'scan_index_forward'}; {'id': '38', 'type': 'True', 'children': []}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43', '53', '62', '73', '82', '91', '100', '115', '124', '138', '152', '161', '175']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '46', 'type': 'dictionary', 'children': ['47', '50']}, {'id': '47', 'type': 'pair', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'TableName'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'table_name'}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'ScanIndexForward'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'scan_index_forward'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'index_name'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'IndexName'"}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'index_name'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'consistent_read'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'ConsistentRead'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'consistent_read'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key_condition_expression'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '81']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'KeyConditionExpression'"}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'key_condition_expression'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'filter_expression'}; {'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': 'payload'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'FilterExpression'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'filter_expression'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeNames'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_names'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108', '109']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeValues'"}; {'id': '108', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'marshall'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'expression_attribute_values'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'projection_expression'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'ProjectionExpression'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'projection_expression'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '126', 'type': 'block', 'children': ['127', '132']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_validate_select'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'Select'"}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'select'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'ExclusiveStartKey'"}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'marshall'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'Limit'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}, {'id': '163', 'type': 'block', 'children': ['164', '169']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '_validate_return_consumed_capacity'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'ReturnConsumedCapacity'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'return_consumed_capacity'}, {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'Query'"}
def query(self, table_name, index_name=None, consistent_read=None, key_condition_expression=None, filter_expression=None, expression_attribute_names=None, expression_attribute_values=None, projection_expression=None, select=None, exclusive_start_key=None, limit=None, scan_index_forward=True, return_consumed_capacity=None): payload = {'TableName': table_name, 'ScanIndexForward': scan_index_forward} if index_name: payload['IndexName'] = index_name if consistent_read is not None: payload['ConsistentRead'] = consistent_read if key_condition_expression: payload['KeyConditionExpression'] = key_condition_expression if filter_expression: payload['FilterExpression'] = filter_expression if expression_attribute_names: payload['ExpressionAttributeNames'] = expression_attribute_names if expression_attribute_values: payload['ExpressionAttributeValues'] = \ utils.marshall(expression_attribute_values) if projection_expression: payload['ProjectionExpression'] = projection_expression if select: _validate_select(select) payload['Select'] = select if exclusive_start_key: payload['ExclusiveStartKey'] = utils.marshall(exclusive_start_key) if limit: payload['Limit'] = limit if return_consumed_capacity: _validate_return_consumed_capacity(return_consumed_capacity) payload['ReturnConsumedCapacity'] = return_consumed_capacity return self.execute('Query', payload)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_gae_versions'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '14', '20', '34', '38', '80']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'SDK_RELEASES_URL'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'releases'}, {'id': '23', 'type': 'call', 'children': ['24', '31']}; {'id': '24', 'type': 'attribute', 'children': ['25', '30']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'items'"}, {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'versions_and_urls'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'releases'}, {'id': '41', 'type': 'block', 'children': ['42', '53', '58']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'PYTHON_RELEASE_RE'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '53', 'type': 'if_statement', 'children': ['54', '56']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'continue_statement', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'versions_and_urls'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'tuple', 'children': ['65', '77']}, {'id': '65', 'type': 'list_comprehension', 'children': ['66', '70']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'release'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'mediaLink'"}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'versions_and_urls'}, {'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '87', 'type': 'lambda', 'children': ['88', '90']}; {'id': '88', 'type': 'lambda_parameters', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'}
def get_gae_versions(): r = requests.get(SDK_RELEASES_URL) r.raise_for_status() releases = r.json().get('items', {}) versions_and_urls = [] for release in releases: match = PYTHON_RELEASE_RE.match(release['name']) if not match: continue versions_and_urls.append( ([int(x) for x in match.groups()], release['mediaLink'])) return sorted(versions_and_urls, key=lambda x: x[0])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_options'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'generic_type', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Dict'}, {'id': '15', 'type': 'type_parameter', 'children': ['16', '18']}; {'id': '16', 'type': 'type', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'try_statement', 'children': ['22', '39']}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '26', 'type': 'generator_expression', 'children': ['27', '36']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'options'}, {'id': '39', 'type': 'except_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ArgumentError'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}
def _parse_options(options: List[str]) -> Dict[str, str]: try: return dict(i.split('=', maxsplit=1) for i in options) except ValueError: raise ArgumentError( f'Option must be in format <key>=<value>, got: {options}')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collapse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '18', '22', '211', '218']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger_ts'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'string', 'children': [], 'value': '"enter collapse"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '17', 'type': 'dictionary', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_dsn'}, {'id': '21', 'type': 'string', 'children': [], 'value': '""'}; {'id': '22', 'type': 'try_statement', 'children': ['23', '183']}, {'id': '23', 'type': 'block', 'children': ['24', '32', '149']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_pc'}, {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"mode"'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '35', 'type': 'block', 'children': ['36', '42', '46', '50', '139']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'dataSetName'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_dsn'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_current'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'not'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '54', 'type': 'block', 'children': ['55', '67', '77', '89']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'logger_ts'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"collapsing: {}"'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"collapsing: {}"'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_current'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_collapse_root'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '87', '88']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '_current'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_pc'}, {'id': '89', 'type': 'try_statement', 'children': ['90', '122']}; {'id': '90', 'type': 'block', 'children': ['91', '103']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '98']}, {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"paleoData"'}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'raw'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"paleoData"'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '109']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'in'}, {'id': '105', 'type': 'string', 'children': [], 'value': '"chronData"'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '117']}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"chronData"'}, {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'raw'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '121', 'type': 'string', 'children': [], 'value': '"chronData"'}; {'id': '122', 'type': 'except_clause', 'children': ['123', '127']}, {'id': '123', 'type': 'as_pattern', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '125', 'type': 'as_pattern_target', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"collapse: Could not collapse an object the dataset: {}, {}"'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': '_collapse_pc'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146', '147', '148']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_current'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_pc'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '156', '168']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '155'], 'value': '=='}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'block', 'children': ['157', '163']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_master'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_dsn'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'string', 'children': [], 'value': '"Created LiPD data: 1 dataset"'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': '"Created LiPD data: {} datasets"'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_master'}, {'id': '183', 'type': 'except_clause', 'children': ['184', '188']}; {'id': '184', 'type': 'as_pattern', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '186', 'type': 'as_pattern_target', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '188', 'type': 'block', 'children': ['189', '199']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'string', 'children': [], 'value': '"Error: Unable to collapse time series, {}"'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'logger_ts'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'string', 'children': [], 'value': '"collapse: Exception: {}"'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'logger_ts'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'string', 'children': [], 'value': '"exit collapse"'}; {'id': '218', 'type': 'return_statement', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_master'}
def collapse(l, raw): logger_ts.info("enter collapse") _master = {} _dsn = "" try: _pc = l[0]["mode"] for entry in l: dsn = entry['dataSetName'] _dsn = dsn _current = entry if dsn not in _master: logger_ts.info("collapsing: {}".format(dsn)) print("collapsing: {}".format(dsn)) _master, _current = _collapse_root(_master, _current, dsn, _pc) try: _master[dsn]["paleoData"] = raw[dsn]["paleoData"] if "chronData" in raw[dsn]: _master[dsn]["chronData"] = raw[dsn]["chronData"] except KeyError as e: print("collapse: Could not collapse an object the dataset: {}, {}".format(dsn, e)) _master = _collapse_pc(_master, _current, dsn, _pc) if len(_master) == 1: _master = _master[_dsn] print("Created LiPD data: 1 dataset") else: print("Created LiPD data: {} datasets".format(len(_master))) except Exception as e: print("Error: Unable to collapse time series, {}".format(e)) logger_ts.error("collapse: Exception: {}".format(e)) logger_ts.info("exit collapse") return _master
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collapseTs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8', '10', '14', '94']}; {'id': '8', 'type': 'global_statement', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': '_timeseries_data'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_d'}, {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '17', '23']}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"Error: Time series data not provided. Pass time series into the function."'}, {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'try_statement', 'children': ['26', '66']}; {'id': '26', 'type': 'block', 'children': ['27', '37', '51', '59']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_raw'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_timeseries_data'}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"time_id"'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'mode_ts'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45', '48']}; {'id': '44', 'type': 'string', 'children': [], 'value': '"collapse"'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '47', 'type': 'string', 'children': [], 'value': '""'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ts'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_d'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'collapse'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ts'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_raw'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_d'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'rm_empty_fields'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_d'}; {'id': '66', 'type': 'except_clause', 'children': ['67', '71']}, {'id': '67', 'type': 'as_pattern', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '69', 'type': 'as_pattern_target', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '71', 'type': 'block', 'children': ['72', '82']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Error: Unable to collapse the time series: {}"'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'e'}; {'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': 'logger_start'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"collapseTs: unable to collapse the time series: {}"'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_d'}
def collapseTs(ts=None): global _timeseries_data _d = {} if not ts: print("Error: Time series data not provided. Pass time series into the function.") else: try: _raw = _timeseries_data[ts[0]["time_id"]] print(mode_ts("collapse", mode="", ts=ts)) _d = collapse(ts, _raw) _d = rm_empty_fields(_d) except Exception as e: print("Error: Unable to collapse the time series: {}".format(e)) logger_start.error("collapseTs: unable to collapse the time series: {}".format(e)) return _d
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'display_results'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'detailed'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '92']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'detailed'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'FILENAME......................................... STATUS..........'"}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'try_statement', 'children': ['23', '64']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26', '47']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'detailed'}; {'id': '26', 'type': 'block', 'children': ['27', '39']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'string', 'children': [], 'value': '"\\n{}"'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"filename"'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'create_detailed_results'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"{:<50}{}"'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '61']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"filename"'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '64', 'type': 'except_clause', 'children': ['65', '69']}, {'id': '65', 'type': 'as_pattern', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '67', 'type': 'as_pattern_target', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '69', 'type': 'block', 'children': ['70', '82']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger_validator_api'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"display_results: Exception: {}"'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"Error: display_results: {}"'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'e'}
def display_results(results, detailed=False): if not detailed: print('FILENAME......................................... STATUS..........') for entry in results: try: if detailed: print("\n{}".format(entry["filename"])) print(create_detailed_results(entry)) else: print("{:<50}{}".format(entry["filename"], entry["status"])) except Exception as e: logger_validator_api.debug("display_results: Exception: {}".format(e)) print("Error: display_results: {}".format(e)) return
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'call_validator_api'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dsn'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'api_data'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '241', '261', '267']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': '_filename'}; {'id': '10', 'type': 'binary_operator', 'children': ['11', '12'], 'value': '+'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'dsn'}; {'id': '12', 'type': 'string', 'children': [], 'value': '".lpd"'}, {'id': '13', 'type': 'try_statement', 'children': ['14', '130', '164', '202']}; {'id': '14', 'type': 'block', 'children': ['15', '24', '34', '46']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'api_data'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'api_data'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '27', 'type': 'dictionary', 'children': ['28', '31']}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'json_payload'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'api_data'}, {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'apikey'"}, {'id': '33', 'type': 'string', 'children': [], 'value': "'lipd_linked'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'http://www.lipd.net/api/validator'"}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '69', '92', '117']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '413'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '56', 'type': 'dictionary', 'children': ['57', '60', '63', '66']}, {'id': '57', 'type': 'pair', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"dat"'}, {'id': '59', 'type': 'dictionary', 'children': []}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"feedback"'}; {'id': '62', 'type': 'dictionary', 'children': []}, {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': '"filename"'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_filename'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"HTTP 413: Request Entity Too Large"'}, {'id': '69', 'type': 'elif_clause', 'children': ['70', '75']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '=='}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '404'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '79', 'type': 'dictionary', 'children': ['80', '83', '86', '89']}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"dat"'}; {'id': '82', 'type': 'dictionary', 'children': []}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"feedback"'}, {'id': '85', 'type': 'dictionary', 'children': []}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"filename"'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '89', 'type': 'pair', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '91', 'type': 'string', 'children': [], 'value': '"HTTP 404: Not Found"'}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '98']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': '=='}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '400'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '102', 'type': 'dictionary', 'children': ['103', '106', '109', '112']}, {'id': '103', 'type': 'pair', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': '"dat"'}, {'id': '105', 'type': 'dictionary', 'children': []}; {'id': '106', 'type': 'pair', 'children': ['107', '108']}, {'id': '107', 'type': 'string', 'children': [], 'value': '"feedback"'}; {'id': '108', 'type': 'dictionary', 'children': []}, {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': '"filename"'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_filename'}; {'id': '112', 'type': 'pair', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '130', 'type': 'except_clause', 'children': ['131', '135']}, {'id': '131', 'type': 'as_pattern', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '133', 'type': 'as_pattern_target', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '135', 'type': 'block', 'children': ['136', '148']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'logger_validator_api'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': '"get_validator_results: TypeError: {}"'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '151', 'type': 'dictionary', 'children': ['152', '155', '158', '161']}; {'id': '152', 'type': 'pair', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': '"dat"'}; {'id': '154', 'type': 'dictionary', 'children': []}, {'id': '155', 'type': 'pair', 'children': ['156', '157']}; {'id': '156', 'type': 'string', 'children': [], 'value': '"feedback"'}, {'id': '157', 'type': 'dictionary', 'children': []}; {'id': '158', 'type': 'pair', 'children': ['159', '160']}, {'id': '159', 'type': 'string', 'children': [], 'value': '"filename"'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '161', 'type': 'pair', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"JSON DECODE ERROR"'}; {'id': '164', 'type': 'except_clause', 'children': ['165', '173']}, {'id': '165', 'type': 'as_pattern', 'children': ['166', '171']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'}, {'id': '171', 'type': 'as_pattern_target', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '173', 'type': 'block', 'children': ['174', '186']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'logger_validator_api'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': '"get_validator_results: ConnectionError: {}"'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '189', 'type': 'dictionary', 'children': ['190', '193', '196', '199']}; {'id': '190', 'type': 'pair', 'children': ['191', '192']}, {'id': '191', 'type': 'string', 'children': [], 'value': '"dat"'}; {'id': '192', 'type': 'dictionary', 'children': []}, {'id': '193', 'type': 'pair', 'children': ['194', '195']}; {'id': '194', 'type': 'string', 'children': [], 'value': '"feedback"'}, {'id': '195', 'type': 'dictionary', 'children': []}; {'id': '196', 'type': 'pair', 'children': ['197', '198']}, {'id': '197', 'type': 'string', 'children': [], 'value': '"filename"'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '199', 'type': 'pair', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '201', 'type': 'string', 'children': [], 'value': '"UNABLE TO REACH SERVER"'}; {'id': '202', 'type': 'except_clause', 'children': ['203', '207']}, {'id': '203', 'type': 'as_pattern', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '205', 'type': 'as_pattern_target', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '207', 'type': 'block', 'children': ['208', '220']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'logger_validator_api'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': '"get_validator_results: Exception: {}"'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '223', 'type': 'dictionary', 'children': ['224', '227', '230', '233']}; {'id': '224', 'type': 'pair', 'children': ['225', '226']}, {'id': '225', 'type': 'string', 'children': [], 'value': '"dat"'}; {'id': '226', 'type': 'dictionary', 'children': []}, {'id': '227', 'type': 'pair', 'children': ['228', '229']}; {'id': '228', 'type': 'string', 'children': [], 'value': '"feedback"'}, {'id': '229', 'type': 'dictionary', 'children': []}; {'id': '230', 'type': 'pair', 'children': ['231', '232']}, {'id': '231', 'type': 'string', 'children': [], 'value': '"filename"'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': '"status"'}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'string', 'children': [], 'value': '"ERROR BEFORE VALIDATION, {}"'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '241', 'type': 'if_statement', 'children': ['242', '244']}; {'id': '242', 'type': 'not_operator', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '248', 'type': 'dictionary', 'children': ['249', '252', '255', '258']}, {'id': '249', 'type': 'pair', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': '"dat"'}, {'id': '251', 'type': 'dictionary', 'children': []}; {'id': '252', 'type': 'pair', 'children': ['253', '254']}, {'id': '253', 'type': 'string', 'children': [], 'value': '"feedback"'}; {'id': '254', 'type': 'dictionary', 'children': []}, {'id': '255', 'type': 'pair', 'children': ['256', '257']}; {'id': '256', 'type': 'string', 'children': [], 'value': '"filename"'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': '_filename'}; {'id': '258', 'type': 'pair', 'children': ['259', '260']}, {'id': '259', 'type': 'string', 'children': [], 'value': '"status"'}; {'id': '260', 'type': 'string', 'children': [], 'value': '"EMPTY RESPONSE"'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '266']}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '265', 'type': 'string', 'children': [], 'value': '"filename"'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}
def call_validator_api(dsn, api_data): _filename = dsn + ".lpd" try: api_data = json.dumps(api_data) payload = {'json_payload': api_data, 'apikey': 'lipd_linked'} response = requests.post('http://www.lipd.net/api/validator', data=payload) if response.status_code == 413: result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "HTTP 413: Request Entity Too Large"} elif response.status_code == 404: result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "HTTP 404: Not Found"} elif response.status_code == 400: result = {"dat": {}, "feedback": {}, "filename": _filename, "status": response.text} else: result = json.loads(response.text) except TypeError as e: logger_validator_api.warning("get_validator_results: TypeError: {}".format(e)) result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "JSON DECODE ERROR"} except requests.exceptions.ConnectionError as e: logger_validator_api.warning("get_validator_results: ConnectionError: {}".format(e)) result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "UNABLE TO REACH SERVER"} except Exception as e: logger_validator_api.debug("get_validator_results: Exception: {}".format(e)) result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "ERROR BEFORE VALIDATION, {}".format(e)} if not result: result = {"dat": {}, "feedback": {}, "filename": _filename, "status": "EMPTY RESPONSE"} result["filename"] = _filename return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_back_links'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '20', '148']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'subscript', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'needs_workflow'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'backlink_creation'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'needs_all_needs'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '24', '29']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'need'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'need'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"links"'}, {'id': '35', 'type': 'block', 'children': ['36', '47', '67']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'link_main'}, {'id': '39', 'type': 'subscript', 'children': ['40', '46']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '47', 'type': 'try_statement', 'children': ['48', '60']}; {'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': 'link_part'}; {'id': '52', 'type': 'subscript', 'children': ['53', '59']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'except_clause', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'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': 'link_part'}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'link_main'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '71', 'type': 'block', 'children': ['72', '92']}; {'id': '72', 'type': 'if_statement', 'children': ['73', '80']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'not'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '75', 'type': 'subscript', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'needs'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'link_main'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"links_back"'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '90']}, {'id': '83', 'type': 'attribute', 'children': ['84', '89']}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'link_main'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"links_back"'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'link_part'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '105']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'link_part'}; {'id': '100', 'type': 'subscript', 'children': ['101', '104']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'link_main'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'parts'"}, {'id': '105', 'type': 'block', 'children': ['106', '133']}; {'id': '106', 'type': 'if_statement', 'children': ['107', '120']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'not'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'links_back'"}, {'id': '109', 'type': 'call', 'children': ['110', '119']}; {'id': '110', 'type': 'attribute', 'children': ['111', '118']}, {'id': '111', 'type': 'subscript', 'children': ['112', '117']}; {'id': '112', 'type': 'subscript', 'children': ['113', '116']}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'link_main'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'parts'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'link_part'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '132']}, {'id': '123', 'type': 'subscript', 'children': ['124', '131']}; {'id': '124', 'type': 'subscript', 'children': ['125', '130']}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'needs'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'link_main'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'parts'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'link_part'}, {'id': '131', 'type': 'string', 'children': [], 'value': "'links_back'"}; {'id': '132', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '146']}, {'id': '135', 'type': 'attribute', 'children': ['136', '145']}; {'id': '136', 'type': 'subscript', 'children': ['137', '144']}, {'id': '137', 'type': 'subscript', 'children': ['138', '143']}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'needs'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'link_main'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'parts'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'link_part'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'links_back'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '155']}; {'id': '150', 'type': 'subscript', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'needs_workflow'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'backlink_creation'"}, {'id': '155', 'type': 'True', 'children': []}
def create_back_links(env): if env.needs_workflow['backlink_creation']: return needs = env.needs_all_needs for key, need in needs.items(): for link in need["links"]: link_main = link.split('.')[0] try: link_part = link.split('.')[1] except IndexError: link_part = None if link_main in needs: if key not in needs[link_main]["links_back"]: needs[link_main]["links_back"].append(key) if link_part is not None: if link_part in needs[link_main]['parts']: if 'links_back' not in needs[link_main]['parts'][link_part].keys(): needs[link_main]['parts'][link_part]['links_back'] = [] needs[link_main]['parts'][link_part]['links_back'].append(key) env.needs_workflow['backlink_creation'] = True
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'CaseGroups'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'unicode_dir'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': '_UNICODE_DIR'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '55', '64', '72', '82', '88']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'togroup'}, {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '17']}, {'id': '13', 'type': 'function_name', 'children': [], 'value': 'DoLine'}; {'id': '14', 'type': 'parameters', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '17', 'type': 'block', 'children': ['18', '26', '34', '41']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '25']}; {'id': '20', 'type': 'tuple_pattern', 'children': ['21', '22', '23', '24']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'foldtype'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'not'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'foldtype'}, {'id': '29', 'type': 'tuple', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"C"'}, {'id': '31', 'type': 'string', 'children': [], 'value': '"S"'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'return_statement', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_UInt'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '53']}, {'id': '43', 'type': 'attribute', 'children': ['44', '52']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'togroup'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '50', 'type': 'list', 'children': ['51'], 'value': '[lower]'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'codes'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ReadUnicodeTable'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '62', '63']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'unicode_dir'}, {'id': '61', 'type': 'string', 'children': [], 'value': '"/CaseFolding.txt"'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'DoLine'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'togroup'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'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': 'groups'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'expression_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'togroup'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'groups'}
def CaseGroups(unicode_dir=_UNICODE_DIR): togroup = {} def DoLine(codes, fields): (_, foldtype, lower, _) = fields if foldtype not in ("C", "S"): return lower = _UInt(lower) togroup.setdefault(lower, [lower]).extend(codes) ReadUnicodeTable(unicode_dir+"/CaseFolding.txt", 4, DoLine) groups = togroup.values() for g in groups: g.sort() groups.sort() return togroup, groups
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'naturalsortkey'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'return_statement', 'children': ['7']}, {'id': '7', 'type': 'list_comprehension', 'children': ['8', '19']}; {'id': '8', 'type': 'conditional_expression', 'children': ['9', '13', '18'], 'value': 'if'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'part'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isdigit'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'part'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'([0-9]+)'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 's'}
def naturalsortkey(s): return [int(part) if part.isdigit() else part for part in re.split('([0-9]+)', s)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'max_variance_genes'}, {'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': 'nbins'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'frac'}; {'id': '10', 'type': 'float', 'children': [], 'value': '0.2'}, {'id': '11', 'type': 'block', 'children': ['12', '16', '53', '61', '74', '83', '177']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '23', '33']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sparse'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'issparse'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '29']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'means'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sparse_mean_var'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35', '44']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'means'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'mean_indices'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'means'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'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': 'n_elements'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '73'], 'value': '/'}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'nbins'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'frac_elements'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '*'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'n_elements'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'frac'}, {'id': '83', 'type': 'for_statement', 'children': ['84', '85', '89']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'nbins'}, {'id': '89', 'type': 'block', 'children': ['90', '106', '123', '129', '137', '150', '156', '170']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'bin_i'}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'mean_indices'}, {'id': '95', 'type': 'slice', 'children': ['96', '99', '100']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '*'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'n_elements'}, {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '105'], 'value': '*'}, {'id': '101', 'type': 'parenthesized_expression', 'children': ['102'], 'value': '()'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '+'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'n_elements'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '112']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '=='}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '-'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'nbins'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'bin_i'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'mean_indices'}; {'id': '118', 'type': 'slice', 'children': ['119', '122']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '*'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'n_elements'}; {'id': '122', 'type': 'colon', 'children': []}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'var_i'}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'bin_i'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'var_sorted'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'var_i'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'top_var_indices'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'var_sorted'}; {'id': '142', 'type': 'slice', 'children': ['143', '149']}, {'id': '143', 'type': 'binary_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': 'bin_i'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'frac_elements'}, {'id': '149', 'type': 'colon', 'children': []}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'bin_i'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'top_var_indices'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '159', 'type': 'list_comprehension', 'children': ['160', '161', '164']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '161', 'type': 'for_in_clause', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '164', 'type': 'if_clause', 'children': ['165']}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '>'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '177', 'type': 'return_statement', 'children': ['178']}
def max_variance_genes(data, nbins=5, frac=0.2): indices = [] if sparse.issparse(data): means, var = sparse_mean_var(data) else: means = data.mean(1) var = data.var(1) mean_indices = means.argsort() n_elements = int(data.shape[0]/nbins) frac_elements = int(n_elements*frac) for i in range(nbins): bin_i = mean_indices[i*n_elements : (i+1)*n_elements] if i==nbins-1: bin_i = mean_indices[i*n_elements :] var_i = var[bin_i] var_sorted = var_i.argsort() top_var_indices = var_sorted[len(bin_i) - frac_elements:] ind = bin_i[top_var_indices] ind = [index for index in ind if var[index]>0] indices.extend(ind) return indices
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ar'}, {'id': '5', 'type': 'block', 'children': ['6', '8', '14', '32']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '8', 'type': 'import_statement', 'children': ['9']}, {'id': '9', 'type': 'aliased_import', 'children': ['10', '13']}; {'id': '10', 'type': 'dotted_name', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'dask'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '24']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ar'}, {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'da'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'core'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Array'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'da'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ar'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_unique'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}
def unique(ar): r import dask.array as da if isinstance(ar, da.core.Array): return da.unique(ar) return _unique(ar)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'polls_get'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '14']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '13']}; {'id': '10', 'type': 'subscript', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'_return_http_data_only'"}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '21', '30']}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'callback'"}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'polls_get_with_http_info'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'dictionary_splat', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '30', 'type': 'else_clause', 'children': ['31']}, {'id': '31', 'type': 'block', 'children': ['32', '43']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '36']}; {'id': '34', 'type': 'tuple_pattern', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'polls_get_with_http_info'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'dictionary_splat', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '43', 'type': 'return_statement', 'children': ['44']}
def polls_get(self, **kwargs): kwargs['_return_http_data_only'] = True if kwargs.get('callback'): return self.polls_get_with_http_info(**kwargs) else: (data) = self.polls_get_with_http_info(**kwargs) return data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_actions'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '35', '63']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '31']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '28']}, {'id': '11', 'type': 'lambda', 'children': ['12', '14']}; {'id': '12', 'type': 'lambda_parameters', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '19', '20'], 'value': 'and'}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '19', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_action'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'parsers'"}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_actions'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'yield', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '59']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '56']}; {'id': '40', 'type': 'lambda', 'children': ['41', '43']}, {'id': '41', 'type': 'lambda_parameters', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47', '48'], 'value': 'and'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '47', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_action'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'parsers'"}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_actions'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'yield', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '63', 'type': 'for_statement', 'children': ['64', '65', '81']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '78']}; {'id': '68', 'type': 'lambda', 'children': ['69', '71']}, {'id': '69', 'type': 'lambda_parameters', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'is_action'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'parsers'"}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_actions'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'yield', 'children': ['84']}
def _sorted_actions(self): for a in filter(lambda _: not _.last and \ not self.is_action(_, 'parsers'), self._actions): yield a for a in filter(lambda _: _.last and \ not self.is_action(_, 'parsers'), self._actions): yield a for a in filter(lambda _: self.is_action(_, 'parsers'), self._actions): yield a
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eigendecomp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '28', '37', '52', '58', '82', '90', '105', '124', '132']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'G'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'lamda'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'eig'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lamda'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'real'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lamda'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '40', 'type': 'subscript', 'children': ['41', '47']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'argsort'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'lamda'}, {'id': '47', 'type': 'slice', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'colon', 'children': []}, {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'lamda_sorted'}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'lamda'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '58', 'type': 'assert_statement', 'children': ['59', '72']}, {'id': '59', 'type': 'call', 'children': ['60', '71']}; {'id': '60', 'type': 'attribute', 'children': ['61', '70']}, {'id': '61', 'type': 'parenthesized_expression', 'children': ['62'], 'value': '()'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '68'], 'value': '>'}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'lamda_sorted'}, {'id': '65', 'type': 'slice', 'children': ['66', '67']}; {'id': '66', 'type': 'colon', 'children': []}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'}, {'id': '69', 'type': 'float', 'children': [], 'value': '1e-10'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"{} not all positive!"'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'lamda_sorted'}, {'id': '79', 'type': 'slice', 'children': ['80', '81']}; {'id': '80', 'type': 'colon', 'children': []}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87', '89']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '87', 'type': 'slice', 'children': ['88']}; {'id': '88', 'type': 'colon', 'children': []}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'factor'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '100']}; {'id': '98', 'type': 'tuple', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'lamda'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '116']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'lamda_sorted'}, {'id': '113', 'type': 'slice', 'children': ['114', '115']}; {'id': '114', 'type': 'colon', 'children': []}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'factor'}; {'id': '120', 'type': 'slice', 'children': ['121', '122', '123']}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'colon', 'children': []}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'd'}; {'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': 'factor'}; {'id': '128', 'type': 'slice', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '130', 'type': 'colon', 'children': []}, {'id': '131', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'expression_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'factor'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'real'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}
def eigendecomp(G, d): N = G.shape[0] lamda, u = np.linalg.eig(G) lamda = np.real(lamda) indices = np.argsort(lamda)[::-1] lamda_sorted = lamda[indices] assert (lamda_sorted[ :d] > -1e-10).all(), "{} not all positive!".format(lamda_sorted[:d]) u = u[:, indices] factor = np.empty((N,), dtype=lamda.dtype) np.sqrt(lamda_sorted[:d], out=factor[0:d]) factor[d:] = 0.0 return factor, np.real(u)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_astrom'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'official'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'%'"}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'provisional'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'%'"}; {'id': '10', 'type': 'block', 'children': ['11', '15', '19', '36', '43', '50']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '14', 'type': 'string', 'children': [], 'value': '"SELECT m.* FROM measure m "'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'augmented_assignment', 'children': ['17', '18'], 'value': '+='}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"LEFT JOIN object o ON m.provisional LIKE o.provisional "'}, {'id': '19', 'type': 'if_statement', 'children': ['20', '22', '27']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'official'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'augmented_assignment', 'children': ['25', '26'], 'value': '+='}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"WHERE o.official IS NULL"'}, {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'augmented_assignment', 'children': ['31', '32'], 'value': '+='}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '%'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"WHERE o.official LIKE \'%s\' "'}; {'id': '34', 'type': 'tuple', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'official'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'augmented_assignment', 'children': ['38', '39'], 'value': '+='}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sql'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': '" AND m.provisional LIKE \'%s\' "'}, {'id': '41', 'type': 'tuple', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'provisional'}, {'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': 'cfeps'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '50', 'type': 'return_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mk_dict'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '59']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'cfeps'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'fetchall'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cfeps'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'description'}
def get_astrom(official='%',provisional='%'): sql= "SELECT m.* FROM measure m " sql+="LEFT JOIN object o ON m.provisional LIKE o.provisional " if not official: sql+="WHERE o.official IS NULL" else: sql+="WHERE o.official LIKE '%s' " % ( official, ) sql+=" AND m.provisional LIKE '%s' " % ( provisional, ) cfeps.execute(sql) return mk_dict(cfeps.fetchall(), cfeps.description)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_by_field'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'issues'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'closed_at'"}; {'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']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '25']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'issues'}, {'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'lambda', 'children': ['20', '22']}; {'id': '20', 'type': 'lambda_parameters', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverse'}
def sorted_by_field(issues, field='closed_at', reverse=False): return sorted(issues, key = lambda i:i[field], reverse=reverse)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_by'}, {'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': 'key_selector'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '25', '49']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Sorts by a key in ascending order.\n Introduces a primary sorting order to the sequence. Additional sort\n criteria should be specified by subsequent calls to then_by() and\n then_by_descending(). Calling order_by() or order_by_descending() on\n the results of a call to order_by() will introduce a new primary\n ordering which will override any already established ordering.\n This method performs a stable sort. The order of two elements with the\n same key will be preserved.\n Note: This method uses deferred execution.\n Args:\n key_selector: A unary function which extracts a key from each\n element using which the result will be ordered.\n Returns:\n An OrderedQueryable over the sorted elements.\n Raises:\n ValueError: If the Queryable is closed.\n TypeError: If the key_selector is not callable.\n '''"}, {'id': '11', 'type': 'if_statement', 'children': ['12', '17']}; {'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': 'closed'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'concatenated_string', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': '"Attempt to call order_by() on a "'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"closed Queryable."'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_callable'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'concatenated_string', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': '"order_by() parameter key_selector={key_selector} "'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"is not callable"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '49', 'type': 'return_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_create_ordered'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '59', '61']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'unary_operator', 'children': ['60'], 'value': '-'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'key_selector'}
def order_by(self, key_selector=identity): '''Sorts by a key in ascending order. Introduces a primary sorting order to the sequence. Additional sort criteria should be specified by subsequent calls to then_by() and then_by_descending(). Calling order_by() or order_by_descending() on the results of a call to order_by() will introduce a new primary ordering which will override any already established ordering. This method performs a stable sort. The order of two elements with the same key will be preserved. Note: This method uses deferred execution. Args: key_selector: A unary function which extracts a key from each element using which the result will be ordered. Returns: An OrderedQueryable over the sorted elements. Raises: ValueError: If the Queryable is closed. TypeError: If the key_selector is not callable. ''' if self.closed(): raise ValueError("Attempt to call order_by() on a " "closed Queryable.") if not is_callable(key_selector): raise TypeError("order_by() parameter key_selector={key_selector} " "is not callable".format(key_selector=repr(key_selector))) return self._create_ordered(iter(self), -1, key_selector)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'then_by'}, {'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': 'key_selector'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '25', '49', '61']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Introduce subsequent ordering to the sequence with an optional key.\n The returned sequence will be sorted in ascending order by the\n selected key.\n Note: This method uses deferred execution.\n Args:\n key_selector: A unary function the only positional argument to\n which is the element value from which the key will be\n selected. The return value should be the key from that\n element.\n Returns:\n An OrderedQueryable over the sorted items.\n Raises:\n ValueError: If the OrderedQueryable is closed().\n TypeError: If key_selector is not callable.\n '''"}, {'id': '11', 'type': 'if_statement', 'children': ['12', '17']}; {'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': 'closed'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'concatenated_string', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': '"Attempt to call then_by() on a "'}; {'id': '24', 'type': 'string', 'children': [], 'value': '"closed OrderedQueryable."'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_callable'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'concatenated_string', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': '"then_by() parameter key_selector={key_selector} "'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"is not callable"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '56']}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_funcs'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'tuple', 'children': ['58', '60']}; {'id': '58', 'type': 'unary_operator', 'children': ['59'], 'value': '-'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'key_selector'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}
def then_by(self, key_selector=identity): '''Introduce subsequent ordering to the sequence with an optional key. The returned sequence will be sorted in ascending order by the selected key. Note: This method uses deferred execution. Args: key_selector: A unary function the only positional argument to which is the element value from which the key will be selected. The return value should be the key from that element. Returns: An OrderedQueryable over the sorted items. Raises: ValueError: If the OrderedQueryable is closed(). TypeError: If key_selector is not callable. ''' if self.closed(): raise ValueError("Attempt to call then_by() on a " "closed OrderedQueryable.") if not is_callable(key_selector): raise TypeError("then_by() parameter key_selector={key_selector} " "is not callable".format(key_selector=repr(key_selector))) self._funcs.append((-1, key_selector)) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_matches'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '35', '44']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '16', 'type': 'list', 'children': ['17', '20', '23', '26', '29', '32'], 'value': '[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME,\n constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME,\n constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME]'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'constants'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'SIZE_FIELDNAME'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'NGRAM_FIELDNAME'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'constants'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'COUNT_FIELDNAME'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'LABEL_FIELDNAME'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'constants'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'WORK_FIELDNAME'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'SIGLUM_FIELDNAME'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ascending'}, {'id': '37', 'type': 'list', 'children': ['38', '39', '40', '41', '42', '43'], 'value': '[False, True, False, True, True, True]'}; {'id': '38', 'type': 'False', 'children': []}, {'id': '39', 'type': 'True', 'children': []}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'True', 'children': []}; {'id': '42', 'type': 'True', 'children': []}, {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'inplace'}
def sort(self): self._matches.sort_values( by=[constants.SIZE_FIELDNAME, constants.NGRAM_FIELDNAME, constants.COUNT_FIELDNAME, constants.LABEL_FIELDNAME, constants.WORK_FIELDNAME, constants.SIGLUM_FIELDNAME], ascending=[False, True, False, True, True, True], inplace=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_labels'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'catalogue'}; {'id': '6', 'type': 'block', 'children': ['7', '94']}, {'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': '_conn'}, {'id': '13', 'type': 'block', 'children': ['14', '27', '31']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_conn'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'execute'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'constants'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'UPDATE_LABELS_SQL'}, {'id': '25', 'type': 'list', 'children': ['26'], 'value': "['']"}; {'id': '26', 'type': 'string', 'children': [], 'value': "''"}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '30', 'type': 'dictionary', 'children': []}, {'id': '31', 'type': 'for_statement', 'children': ['32', '35', '40']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'work'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'catalogue'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '55', '70', '80']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', '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': '_conn'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'constants'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'UPDATE_LABEL_SQL'}; {'id': '52', 'type': 'list', 'children': ['53', '54'], 'value': '[label, work]'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'work'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'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': '_conn'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'constants'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'SELECT_TEXT_TOKEN_COUNT_SQL'}; {'id': '68', 'type': 'list', 'children': ['69'], 'value': '[work]'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'work'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'token_count'}, {'id': '73', 'type': 'subscript', 'children': ['74', '79']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'fetchone'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'string', 'children': [], 'value': "'token_count'"}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '93'], 'value': '+'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'token_count'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'labels'}
def _set_labels(self, catalogue): with self._conn: self._conn.execute(constants.UPDATE_LABELS_SQL, ['']) labels = {} for work, label in catalogue.items(): self._conn.execute(constants.UPDATE_LABEL_SQL, [label, work]) cursor = self._conn.execute( constants.SELECT_TEXT_TOKEN_COUNT_SQL, [work]) token_count = cursor.fetchone()['token_count'] labels[label] = labels.get(label, 0) + token_count return labels
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_fn_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '22', '29', '38', '50', '68']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'all_args'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_all_args'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'required_args'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get_required_args'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fn_kwargs'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pick_kwargs'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'all_args'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'missing_args'}, {'id': '41', 'type': 'list_comprehension', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'required_args'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'fn_kwargs'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'missing_args'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'raise_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}, {'id': '59', 'type': 'concatenated_string', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'The following args are missing for the function '"}, {'id': '61', 'type': 'string', 'children': [], 'value': "'{}: {}.'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'missing_args'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'fn_kwargs'}
def get_fn_args(fn, kwargs: dict, prefix: str = None): all_args = get_all_args(fn) required_args = get_required_args(fn) fn_kwargs = pick_kwargs(kwargs, all_args, prefix) missing_args = [arg for arg in required_args if arg not in fn_kwargs] if missing_args: raise ValueError( 'The following args are missing for the function ' '{}: {}.'.format(fn.__name__, missing_args) ) return fn_kwargs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pick_kwargs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8', '12']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'required_args'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '16']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '38', '42', '86', '98', '113']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'picked'}, {'id': '21', 'type': 'dictionary_comprehension', 'children': ['22', '25', '34']}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '29']}; {'id': '26', 'type': 'pattern_list', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'if_clause', 'children': ['35']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'required_args'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'prefixed'}, {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '44', 'type': 'block', 'children': ['45', '51']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'__'"}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'prefixed'}; {'id': '54', 'type': 'dictionary_comprehension', 'children': ['55', '62', '71']}, {'id': '55', 'type': 'pair', 'children': ['56', '61']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_remove_prefix'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '66']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'if_clause', 'children': ['72']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '79'], 'value': 'and'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '85'], 'value': 'in'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_remove_prefix'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'required_args'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'conflicting_args'}, {'id': '89', 'type': 'list_comprehension', 'children': ['90', '91', '94']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'picked'}; {'id': '94', 'type': 'if_clause', 'children': ['95']}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'prefixed'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'conflicting_args'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'concatenated_string', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'Both prefixed and unprefixed args were specified '"}, {'id': '109', 'type': 'string', 'children': [], 'value': "'for the following parameters: {}'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'conflicting_args'}, {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'tz'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'picked'}
def pick_kwargs(kwargs: dict, required_args: list, prefix: str = None): picked = {k: v for k, v in kwargs.items() if k in required_args} prefixed = {} if prefix: prefix = prefix + '__' prefixed = { _remove_prefix(k, prefix): v for k, v in kwargs.items() if k.startswith(prefix) and _remove_prefix(k, prefix) in required_args } conflicting_args = [k for k in picked if k in prefixed] if conflicting_args: raise ValueError( 'Both prefixed and unprefixed args were specified ' 'for the following parameters: {}'.format(conflicting_args) ) return tz.merge(picked, prefixed)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'query_type'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_QUERY_TYPE'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '34', '72']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'statement'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'arguments'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_build_search'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'arguments'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'QueryResults'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'AND'"}; {'id': '34', 'type': 'with_statement', 'children': ['35', '43']}, {'id': '35', 'type': 'with_clause', 'children': ['36']}; {'id': '36', 'type': 'with_item', 'children': ['37']}, {'id': '37', 'type': 'as_pattern', 'children': ['38', '41']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'db_connect'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'as_pattern_target', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'db_connection'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'with_statement', 'children': ['45', '55']}, {'id': '45', 'type': 'with_clause', 'children': ['46']}; {'id': '46', 'type': 'with_item', 'children': ['47']}, {'id': '47', 'type': 'as_pattern', 'children': ['48', '53']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'db_connection'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'as_pattern_target', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '55', 'type': 'block', 'children': ['56', '64']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'execute'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'statement'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'arguments'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'search_results'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'fetchall'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'QueryResults'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'search_results'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'query'}
def search(query, query_type=DEFAULT_QUERY_TYPE): statement, arguments = _build_search(query) if statement is None and arguments is None: return QueryResults([], [], 'AND') with db_connect() as db_connection: with db_connection.cursor() as cursor: cursor.execute(statement, arguments) search_results = cursor.fetchall() return QueryResults(search_results, query, query_type)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_tdms_files'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '5', 'type': 'block', 'children': ['6', '19', '38', '56']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'path'}, {'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': 'pathlib'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Path'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'resolve'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tdmslist'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '24', '32']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rglob'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"*.tdms"'}; {'id': '32', 'type': 'if_clause', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'is_file'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tdmslist'}, {'id': '41', 'type': 'list_comprehension', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tdmslist'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'string', 'children': [], 'value': '"_traces.tdms"'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}
def get_tdms_files(directory): path = pathlib.Path(directory).resolve() tdmslist = [r for r in path.rglob("*.tdms") if r.is_file()] tdmslist = [r for r in tdmslist if not r.name.endswith("_traces.tdms")] return sorted(tdmslist)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'footrule_dist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'params1'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '25', '35', '70']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'assert_statement', 'children': ['12']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '16'], 'value': 'or'}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '=='}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'params1'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ranks1'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rankdata'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'params1'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"average"'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39', '58']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'params2'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ranks2'}, {'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': 'arange'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '55']}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '54'], 'value': '+'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'params1'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ranks2'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'rankdata'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"average"'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '-'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ranks1'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ranks2'}
def footrule_dist(params1, params2=None): r assert params2 is None or len(params1) == len(params2) ranks1 = rankdata(params1, method="average") if params2 is None: ranks2 = np.arange(1, len(params1) + 1, dtype=float) else: ranks2 = rankdata(params2, method="average") return np.sum(np.abs(ranks1 - ranks2))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'kendalltau_dist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'params1'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '25', '35', '70', '80', '87', '98']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'assert_statement', 'children': ['12']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '16'], 'value': 'or'}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '=='}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'params1'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ranks1'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'rankdata'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'params1'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"ordinal"'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39', '58']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'params2'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ranks2'}, {'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': 'arange'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '55']}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '54'], 'value': '+'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'params1'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '58', 'type': 'else_clause', 'children': ['59']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ranks2'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'rankdata'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'params2'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"ordinal"'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'tau'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'kendalltau'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ranks1'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ranks2'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'n_items'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'params1'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'n_pairs'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '97'], 'value': '/'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '*'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'n_items'}, {'id': '93', 'type': 'parenthesized_expression', 'children': ['94'], 'value': '()'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '-'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'n_items'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'round'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '109'], 'value': '/'}, {'id': '103', 'type': 'parenthesized_expression', 'children': ['104'], 'value': '()'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '-'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'n_pairs'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '*'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'n_pairs'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'tau'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '2'}
def kendalltau_dist(params1, params2=None): r assert params2 is None or len(params1) == len(params2) ranks1 = rankdata(params1, method="ordinal") if params2 is None: ranks2 = np.arange(1, len(params1) + 1, dtype=float) else: ranks2 = rankdata(params2, method="ordinal") tau, _ = kendalltau(ranks1, ranks2) n_items = len(params1) n_pairs = n_items * (n_items - 1) / 2 return round((n_pairs - n_pairs * tau) / 2)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_sort_string'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '23', '27', '100', '107']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'list', 'children': ['13'], 'value': "['_score']"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'_score'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'rsplit'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "','"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '26', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '30', 'type': 'block', 'children': ['31', '39', '53', '73', '81']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'se'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '42', 'type': 'conditional_expression', 'children': ['43', '44', '52'], 'value': 'if'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '51'], 'value': '=='}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '47', 'type': 'slice', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'colon', 'children': []}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'asc'"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '56', 'type': 'conditional_expression', 'children': ['57', '62', '72'], 'value': 'if'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '59', 'type': 'slice', 'children': ['60', '61']}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '69'], 'value': 'in'}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '65', 'type': 'slice', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'colon', 'children': []}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'list', 'children': ['70', '71'], 'value': "['-', '+']"}; {'id': '70', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '71', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'se'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sortlist'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'dictionary', 'children': ['88']}; {'id': '88', 'type': 'pair', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '90', 'type': 'dictionary', 'children': ['91', '94', '97']}, {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': '"order"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"unmapped_type"'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"string"'}, {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"missing"'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"_last"'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sortlist'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'_score'"}, {'id': '107', 'type': 'return_statement', 'children': ['108']}
def parse_sort_string(sort): if sort is None: return ['_score'] l = sort.rsplit(',') sortlist = [] for se in l: se = se.strip() order = 'desc' if se[0:1] == '-' else 'asc' field = se[1:] if se[0:1] in ['-', '+'] else se field = field.strip() sortlist.append({field: {"order": order, "unmapped_type": "string", "missing": "_last"}}) sortlist.append('_score') return sortlist
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_config_dir'}, {'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': 'pattern'}, {'id': '7', 'type': 'string', 'children': [], 'value': '"*.config"'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'configspec'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'allow_errors'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '24', '37', '55', '62', '68', '136']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'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': '"Loading all files matching {0} in {1}"'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '40', 'type': 'call', 'children': ['41', '54']}, {'id': '41', 'type': 'attribute', 'children': ['42', '53']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Globber'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46', '50']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '48', 'type': 'list', 'children': ['49'], 'value': '[pattern]'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '52', 'type': 'False', 'children': []}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'ConfigObj'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '71', 'type': 'block', 'children': ['72', '84', '117', '129']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"- Loading config for {0}"'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '84', 'type': 'try_statement', 'children': ['85', '96']}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'ConfigObj'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'configspec'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'configspec'}; {'id': '96', 'type': 'except_clause', 'children': ['97', '98', '99']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ConfigObjError'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'coe'}, {'id': '99', 'type': 'block', 'children': ['100', '116']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '"An error occurred while parsing {0}: {1}"'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'coe'}; {'id': '116', 'type': 'continue_statement', 'children': []}, {'id': '117', 'type': 'if_statement', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'configspec'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'Validator'}; {'id': '128', 'type': 'argument_list', 'children': []}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '136', 'type': 'return_statement', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'config'}
def get_config_dir(path, pattern="*.config", configspec=None, allow_errors=False): logger = logging.getLogger(__name__) logger.debug("Loading all files matching {0} in {1}".format(pattern, path)) files = Globber(path, include=[pattern], recursive=False).glob() files = sorted(files) config = ConfigObj() for filename in files: logger.debug("- Loading config for {0}".format(filename)) try: conf = ConfigObj(filename, configspec=configspec) except ConfigObjError, coe: logger.error("An error occurred while parsing {0}: {1}".format(filename, str(coe))) continue if configspec: conf.validate(Validator()) config.merge(conf) return config
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_first_instance_aws'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '51', '114', '174']}, {'id': '5', 'type': 'try_statement', 'children': ['6', '35']}; {'id': '6', 'type': 'block', 'children': ['7', '23', '29']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'instance_details'}; {'id': '10', 'type': 'call', 'children': ['11', '22']}, {'id': '11', 'type': 'attribute', 'children': ['12', '21']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'http://169.254.169.254/latest/dynamic/instance-identity/document'"}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'instance_id'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'instance_details'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'instanceId'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'instance_region'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'instance_details'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'region'"}, {'id': '35', 'type': 'except_clause', 'children': ['36', '45']}; {'id': '36', 'type': 'as_pattern', 'children': ['37', '43']}, {'id': '37', 'type': 'tuple', 'children': ['38', '41', '42']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'RequestException'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '43', 'type': 'as_pattern_target', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'raise_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'StackInterrogationException'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '51', 'type': 'try_statement', 'children': ['52', '96', '107']}; {'id': '52', 'type': 'block', 'children': ['53', '65', '77', '86']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'autoscaling_client'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'boto3'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'autoscaling'"}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'region_name'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'instance_region'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'autoscaling_client'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'describe_auto_scaling_instances'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'InstanceIds'}, {'id': '75', 'type': 'list', 'children': ['76'], 'value': '[instance_id]'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'instance_id'}, {'id': '77', 'type': 'assert_statement', 'children': ['78']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '85'], 'value': '=='}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'AutoScalingInstances'"}, {'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': 'autoscaling_group'}, {'id': '89', 'type': 'subscript', 'children': ['90', '95']}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'AutoScalingInstances'"}; {'id': '94', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'AutoScalingGroupName'"}; {'id': '96', 'type': 'except_clause', 'children': ['97', '101']}, {'id': '97', 'type': 'as_pattern', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ClientError'}, {'id': '99', 'type': 'as_pattern_target', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'StackInterrogationException'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '107', 'type': 'except_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'raise_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'InstanceNotInAsgException'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'try_statement', 'children': ['115', '161']}, {'id': '115', 'type': 'block', 'children': ['116', '128', '137']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'autoscaling_client'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'describe_auto_scaling_groups'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'AutoScalingGroupNames'}; {'id': '126', 'type': 'list', 'children': ['127'], 'value': '[autoscaling_group]'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'autoscaling_group'}; {'id': '128', 'type': 'assert_statement', 'children': ['129']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '136'], 'value': '=='}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'AutoScalingGroups'"}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'autoscaling_group_instance_ids'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '142', 'type': 'generator_expression', 'children': ['143', '146', '155']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'InstanceId'"}; {'id': '146', 'type': 'for_in_clause', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '148', 'type': 'subscript', 'children': ['149', '154']}, {'id': '149', 'type': 'subscript', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'AutoScalingGroups'"}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'Instances'"}, {'id': '155', 'type': 'if_clause', 'children': ['156']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': '=='}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'LifecycleState'"}; {'id': '160', 'type': 'string', 'children': [], 'value': "'InService'"}, {'id': '161', 'type': 'except_clause', 'children': ['162', '168']}; {'id': '162', 'type': 'as_pattern', 'children': ['163', '166']}, {'id': '163', 'type': 'tuple', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ClientError'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}; {'id': '166', 'type': 'as_pattern_target', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'raise_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'StackInterrogationException'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '174', 'type': 'return_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'boolean_operator', 'children': ['179', '180'], 'value': 'and'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'autoscaling_group_instance_ids'}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '184'], 'value': '=='}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'autoscaling_group_instance_ids'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}
def is_first_instance_aws(): try: instance_details = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document', timeout=5).json() instance_id = instance_details['instanceId'] instance_region = instance_details['region'] except (requests.RequestException, ValueError, KeyError) as e: raise StackInterrogationException(e) try: autoscaling_client = boto3.client('autoscaling', region_name=instance_region) response = autoscaling_client.describe_auto_scaling_instances(InstanceIds=[instance_id]) assert len(response['AutoScalingInstances']) == 1 autoscaling_group = response['AutoScalingInstances'][0]['AutoScalingGroupName'] except ClientError as e: raise StackInterrogationException(e) except AssertionError: raise InstanceNotInAsgException() try: response = autoscaling_client.describe_auto_scaling_groups(AutoScalingGroupNames=[autoscaling_group]) assert len(response['AutoScalingGroups']) == 1 autoscaling_group_instance_ids = sorted( instance['InstanceId'] for instance in response['AutoScalingGroups'][0]['Instances'] if instance['LifecycleState'] == 'InService' ) except (ClientError, AssertionError) as e: raise StackInterrogationException(e) return bool(autoscaling_group_instance_ids and autoscaling_group_instance_ids[0] == instance_id)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'creation_ordered'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}, {'id': '5', 'type': 'block', 'children': ['6', '20', '26', '67', '74', '88', '95', '104']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'next_index'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'functools'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '__init__orig'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '__init__'}; {'id': '26', 'type': 'decorated_definition', 'children': ['27', '38']}, {'id': '27', 'type': 'decorator', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'functools'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'wraps'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '__init__orig'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'assigned'}; {'id': '36', 'type': 'list', 'children': ['37'], 'value': "['__doc__']"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'__doc__'"}; {'id': '38', 'type': 'function_definition', 'children': ['39', '40', '46']}, {'id': '39', 'type': 'function_name', 'children': [], 'value': '__init__'}; {'id': '40', 'type': 'parameters', 'children': ['41', '42', '44']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'list_splat_pattern', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '44', 'type': 'dictionary_splat_pattern', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '46', 'type': 'block', 'children': ['47', '58']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'object'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '__setattr__'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'_index'"}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'next_index'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '__init__orig'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '65']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'list_splat', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '65', 'type': 'dictionary_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72', '73']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'__init__'"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '__init__'}; {'id': '74', 'type': 'function_definition', 'children': ['75', '76', '79']}, {'id': '75', 'type': 'function_name', 'children': [], 'value': '__lt__'}; {'id': '76', 'type': 'parameters', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'other'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '<'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_index'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'other'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'__lt__'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '__lt__'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'functools'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'total_ordering'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'class_to_decorate'}
def creation_ordered(class_to_decorate): next_index = functools.partial(next, itertools.count()) __init__orig = class_to_decorate.__init__ @functools.wraps(__init__orig, assigned=['__doc__']) def __init__(self, *args, **kwargs): object.__setattr__(self, '_index', next_index()) __init__orig(self, *args, **kwargs) setattr(class_to_decorate, '__init__', __init__) def __lt__(self, other): return self._index < other._index setattr(class_to_decorate, '__lt__', __lt__) class_to_decorate = functools.total_ordering(class_to_decorate) return class_to_decorate
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_members'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'member_class'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'is_member'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_parameter'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '32', '38', '82', '170', '176', '233']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'member_class'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'is_member'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"get_members either needs a member_class parameter or an is_member check function (or both)"'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '__bases__'}, {'id': '43', 'type': 'block', 'children': ['44', '75']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '48', '65']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_parameter'}, {'id': '47', 'type': 'None', 'children': []}; {'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': 'inherited_members'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_members'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '59', '62']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'member_class'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'member_class'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'is_member'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'is_member'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '65', 'type': 'else_clause', 'children': ['66']}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'inherited_members'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_declared'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_parameter'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'inherited_members'}; {'id': '82', 'type': 'function_definition', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'function_name', 'children': [], 'value': 'generate_member_bindings'}; {'id': '84', 'type': 'parameters', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '91']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '91', 'type': 'block', 'children': ['92', '101', '109']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '99']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'__'"}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'continue_statement', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '119', '125', '140']}; {'id': '110', 'type': 'boolean_operator', 'children': ['111', '114'], 'value': 'and'}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'member_class'}, {'id': '113', 'type': 'None', 'children': []}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'member_class'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'yield', 'children': ['122']}; {'id': '122', 'type': 'expression_list', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '125', 'type': 'elif_clause', 'children': ['126', '134']}; {'id': '126', 'type': 'boolean_operator', 'children': ['127', '130'], 'value': 'and'}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'is_member'}, {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'is_member'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'yield', 'children': ['137']}, {'id': '137', 'type': 'expression_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '140', 'type': 'elif_clause', 'children': ['141', '162']}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '155'], 'value': 'and'}; {'id': '142', 'type': 'boolean_operator', 'children': ['143', '149'], 'value': 'and'}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '148'], 'value': 'is'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '154'], 'value': '=='}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'member_class'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'raise_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '%'}; {'id': '168', 'type': 'string', 'children': [], 'value': '"\'%s\' is a one-tuple containing what we are looking for. Trailing comma much? Don\'t... just don\'t."'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'bindings'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'generate_member_bindings'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'if_statement', 'children': ['177', '180', '224']}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '179', 'type': 'None', 'children': []}; {'id': '180', 'type': 'block', 'children': ['181', '217']}, {'id': '181', 'type': 'try_statement', 'children': ['182', '201']}; {'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': 'sorted_bindings'}; {'id': '186', 'type': 'call', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'bindings'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '192', 'type': 'lambda', 'children': ['193', '195']}, {'id': '193', 'type': 'lambda_parameters', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '201', 'type': 'except_clause', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'if_statement', 'children': ['205', '208', '214']}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'is'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'default_sort_key'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'raise_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'string', 'children': [], 'value': "'Missing member ordering definition. Use @creation_ordered or specify sort_key'"}; {'id': '214', 'type': 'else_clause', 'children': ['215']}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'raise_statement', 'children': []}, {'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': 'members'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'sorted_bindings'}; {'id': '224', 'type': 'else_clause', 'children': ['225']}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'members'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'bindings'}, {'id': '233', 'type': 'return_statement', 'children': ['234']}
def get_members(cls, member_class=None, is_member=None, sort_key=None, _parameter=None): if member_class is None and is_member is None: raise TypeError("get_members either needs a member_class parameter or an is_member check function (or both)") members = OrderedDict() for base in cls.__bases__: if _parameter is None: inherited_members = get_members(base, member_class=member_class, is_member=is_member, sort_key=sort_key) else: inherited_members = get_declared(base, _parameter) members.update(inherited_members) def generate_member_bindings(): for name in cls.__dict__: if name.startswith('__'): continue obj = getattr(cls, name) if member_class is not None and isinstance(obj, member_class): yield name, obj elif is_member is not None and is_member(obj): yield name, obj elif type(obj) is tuple and len(obj) == 1 and isinstance(obj[0], member_class): raise TypeError("'%s' is a one-tuple containing what we are looking for. Trailing comma much? Don't... just don't." % name) bindings = generate_member_bindings() if sort_key is not None: try: sorted_bindings = sorted(bindings, key=lambda x: sort_key(x[1])) except AttributeError: if sort_key is default_sort_key: raise TypeError('Missing member ordering definition. Use @creation_ordered or specify sort_key') else: raise members.update(sorted_bindings) else: members.update(bindings) return members
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_field'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'field_vals'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '51', '70']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_normalize_field_name'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24', '29', '39']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '>'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'direction'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '29', 'type': 'elif_clause', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '<'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '39', 'type': 'else_clause', 'children': ['40']}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'string', 'children': [], 'value': '"direction {} is undefined"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'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': 'fields_sort'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '60', 'type': 'list', 'children': ['61', '62', '63'], 'value': '[direction, field_name, list(field_vals) if field_vals else field_vals]'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '63', 'type': 'conditional_expression', 'children': ['64', '68', '69'], 'value': 'if'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'field_vals'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'field_vals'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'field_vals'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort_field(self, field_name, direction, field_vals=None): field_name = self._normalize_field_name(field_name) if direction > 0: direction = 1 elif direction < 0: direction = -1 else: raise ValueError("direction {} is undefined".format(direction)) self.fields_sort.append(field_name, [direction, field_name, list(field_vals) if field_vals else field_vals]) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_photometry_categorize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '13', '22', '31', '39', '45', '62', '66', '70', '87', '91', '115', '189']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''Put every point in its category.\n levels must be sorted.'''"}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ys'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ys'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '44', 'type': 'argument_list', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '48', 'type': 'call', 'children': ['49', '61']}, {'id': '49', 'type': 'attribute', 'children': ['50', '60']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ys'}; {'id': '52', 'type': 'slice', 'children': ['53', '59']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '58'], 'value': '//'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ys'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '59', 'type': 'colon', 'children': []}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'augmented_assignment', 'children': ['64', '65'], 'value': '/='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '69', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '73', 'type': 'call', 'children': ['74', '86']}; {'id': '74', 'type': 'attribute', 'children': ['75', '85']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ys'}, {'id': '77', 'type': 'slice', 'children': ['78', '84']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '83'], 'value': '//'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ys'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '84', 'type': 'colon', 'children': []}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '90', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '95']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '108']}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'moves'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '114'], 'value': '+'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'levels'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '115', 'type': 'for_statement', 'children': ['116', '119', '124', '174']}; {'id': '116', 'type': 'pattern_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'levels'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tags'}; {'id': '124', 'type': 'block', 'children': ['125', '131']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'indc'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '<'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '131', 'type': 'if_statement', 'children': ['132', '137']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'indc'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'block', 'children': ['138', '144', '150', '160', '167']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'x1'}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'indc'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'y1'}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'indc'}; {'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': 'result'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'tuple', 'children': ['157', '158', '159']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'x1'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'y1'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '165', 'type': 'unary_operator', 'children': ['166'], 'value': '~'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'indc'}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '~'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'indc'}; {'id': '174', 'type': 'else_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'tuple', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '187', 'type': 'unary_operator', 'children': ['188'], 'value': '-'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'expression_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '192', 'type': 'tuple', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'm'}
def check_photometry_categorize(x, y, levels, tags=None): '''Put every point in its category. levels must be sorted.''' x = numpy.asarray(x) y = numpy.asarray(y) ys = y.copy() ys.sort() m = ys[len(ys) // 2:].mean() y /= m m = 1.0 s = ys[len(ys) // 2:].std() result = [] if tags is None: tags = list(six.moves.range(len(levels) + 1)) for l, t in zip(levels, tags): indc = y < l if indc.any(): x1 = x[indc] y1 = y[indc] result.append((x1, y1, t)) x = x[~indc] y = y[~indc] else: result.append((x, y, tags[-1])) return result, (m, s)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_normalize_sort_SQL'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'field_vals'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort_dir_str'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '45', '60', '64', '92', '99', '108']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'fvi'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17', '29']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_dir_str'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'ASC'"}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fvi'}, {'id': '21', 'type': 'generator_expression', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '23', 'type': 'for_in_clause', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'field_vals'}, {'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': 'fvi'}; {'id': '34', 'type': 'generator_expression', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'field_vals'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}; {'id': '48', 'type': 'list', 'children': ['49'], 'value': "[' CASE {}'.format(self._normalize_name(field_name))]"}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "' CASE {}'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_normalize_name'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'query_args'}, {'id': '63', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '68', '69']}, {'id': '65', 'type': 'pattern_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'fvi'}, {'id': '69', 'type': 'block', 'children': ['70', '85']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "' WHEN {} THEN {}'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'val_placeholder'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'query_args'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': "' END'"}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'expression_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'query_sort_str'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'query_args'}
def _normalize_sort_SQL(self, field_name, field_vals, sort_dir_str): fvi = None if sort_dir_str == 'ASC': fvi = (t for t in enumerate(field_vals)) else: fvi = (t for t in enumerate(reversed(field_vals))) query_sort_str = [' CASE {}'.format(self._normalize_name(field_name))] query_args = [] for i, v in fvi: query_sort_str.append(' WHEN {} THEN {}'.format(self.val_placeholder, i)) query_args.append(v) query_sort_str.append(' END') query_sort_str = "\n".join(query_sort_str) return query_sort_str, query_args
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_process'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '30', '49', '58']}, {'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': 'mlh'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'mlw'}; {'id': '12', 'type': 'expression_list', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'max_line_height'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'max_line_width'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'uint32'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '44'], 'value': '+'}; {'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '*'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mlw'}; {'id': '36', 'type': 'parenthesized_expression', 'children': ['37'], 'value': '()'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '43'], 'value': '//'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40', '42']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '40', 'type': 'slice', 'children': ['41']}, {'id': '41', 'type': 'colon', 'children': []}; {'id': '42', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mlh'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46', '48']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '46', 'type': 'slice', 'children': ['47']}, {'id': '47', 'type': 'colon', 'children': []}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_order'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'numpy'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_order'}
def _process(self, segments): mlh, mlw = self.max_line_height, self.max_line_width s = segments.astype(numpy.uint32) order = mlw * (s[:, 1] // mlh) + s[:, 0] sort_order = numpy.argsort(order) return segments[sort_order]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatten'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pval'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'sortby'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"cor"'}, {'id': '9', 'type': 'block', 'children': ['10', '18', '30', '63', '80', '133']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '13', 'type': 'subscript', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'triu_indices'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tab'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '45']}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '40', 'type': 'list', 'children': ['41', '42', '43', '44'], 'value': "['i', 'j', 'cor', 'pval']"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'i'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'j'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'cor'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'pval'"}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '47', 'type': 'subscript', 'children': ['48', '51', '54', '57', '60']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'c_'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'rho'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pval'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '70']}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tab'}, {'id': '67', 'type': 'list', 'children': ['68', '69'], 'value': '[\'i\', "j"]'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'i'"}, {'id': '69', 'type': 'string', 'children': [], 'value': '"j"'}; {'id': '70', 'type': 'call', 'children': ['71', '78']}, {'id': '71', 'type': 'attribute', 'children': ['72', '77']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '74', 'type': 'list', 'children': ['75', '76'], 'value': '[\'i\', "j"]'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'i'"}; {'id': '76', 'type': 'string', 'children': [], 'value': '"j"'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84', '113']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '=='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sortby'}, {'id': '83', 'type': 'string', 'children': [], 'value': '"cor"'}; {'id': '84', 'type': 'block', 'children': ['85', '98']}, {'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': 'tab'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'abscor'"}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tab'}, {'id': '97', 'type': 'string', 'children': [], 'value': "'cor'"}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '107', '110']}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'abscor'"}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '109', 'type': 'True', 'children': []}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '112', 'type': 'False', 'children': []}, {'id': '113', 'type': 'elif_clause', 'children': ['114', '117']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sortby'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"pval"'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '127', '130']}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'pval'"}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '129', 'type': 'True', 'children': []}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '132', 'type': 'True', 'children': []}, {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '136', 'type': 'list', 'children': ['137', '138', '139', '140'], 'value': '["i", "j", "cor", "pval"]'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"i"'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"j"'}, {'id': '139', 'type': 'string', 'children': [], 'value': '"cor"'}
def flatten(rho, pval, sortby="cor"): n = rho.shape[0] idx = np.triu_indices(n, k=1) tab = pd.DataFrame( columns=['i', 'j', 'cor', 'pval'], data=np.c_[idx[0], idx[1], rho[idx], pval[idx]]) tab[['i', "j"]] = tab[['i', "j"]].astype(int) if sortby == "cor": tab['abscor'] = np.abs(tab['cor']) tab.sort_values(by='abscor', inplace=True, ascending=False) elif sortby == "pval": tab.sort_values(by='pval', inplace=True, ascending=True) return tab[["i", "j", "cor", "pval"]]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'has_code'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'incorrect_msg'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"The checker expected to find `{{text}}` in your command."'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'fixed'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '19', '34', '60']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stu_code'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'student_code'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '22', 'type': 'conditional_expression', 'children': ['23', '26', '27'], 'value': 'if'}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stu_code'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'fixed'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stu_code'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '37']}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '37', 'type': 'block', 'children': ['38', '53']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_msg'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'build_message'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'incorrect_msg'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'fmt_kwargs'}, {'id': '49', 'type': 'dictionary', 'children': ['50']}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'do_test'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_msg'}; {'id': '60', 'type': 'return_statement', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'state'}
def has_code(state, text, incorrect_msg="The checker expected to find `{{text}}` in your command.", fixed=False): stu_code = state.student_code res = text in stu_code if fixed else re.search(text, stu_code) if not res: _msg = state.build_message(incorrect_msg, fmt_kwargs={ 'text': text }) state.do_test(_msg) return state
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'topports'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'records'"}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'return_format'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '32', '67']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'list', 'children': ['26', '27', '28'], 'value': "['topports', sort_by, str(limit)]"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'topports'"}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_by'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'try_statement', 'children': ['36', '53']}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'list', 'children': ['46', '47'], 'value': '[uri, date.strftime("%Y-%m-%d")]'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'uri'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'strftime'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d"'}, {'id': '53', 'type': 'except_clause', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'uri'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': '[uri, date]'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_get'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'uri'}
def topports(sort_by='records', limit=10, date=None, return_format=None): uri = '/'.join(['topports', sort_by, str(limit)]) if date: try: uri = '/'.join([uri, date.strftime("%Y-%m-%d")]) except AttributeError: uri = '/'.join([uri, date]) return _get(uri, return_format)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'all_nodes_that_receive'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'service_configuration'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'run_only'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'deploy_to_only'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '21', '32', '40', '51', '60', '88']}, {'id': '15', 'type': 'assert_statement', 'children': ['16']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'parenthesized_expression', 'children': ['18'], 'value': '()'}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '20'], 'value': 'and'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'run_only'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'deploy_to_only'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'service_configuration'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'service_configuration'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'read_services_configuration'}, {'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': 'runs_on'}, {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'service_configuration'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'runs_on'"}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'deployed_to'}, {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'service_configuration'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'deployed_to'"}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'deployed_to'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'deployed_to'}, {'id': '59', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '62', '67', '74']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'run_only'}; {'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': 'result'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'runs_on'}, {'id': '67', 'type': 'elif_clause', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'deploy_to_only'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'deployed_to'}; {'id': '74', 'type': 'else_clause', 'children': ['75']}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '84'], 'value': '|'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'runs_on'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'deployed_to'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'result'}
def all_nodes_that_receive(service, service_configuration=None, run_only=False, deploy_to_only=False): assert not (run_only and deploy_to_only) if service_configuration is None: service_configuration = read_services_configuration() runs_on = service_configuration[service]['runs_on'] deployed_to = service_configuration[service].get('deployed_to') if deployed_to is None: deployed_to = [] if run_only: result = runs_on elif deploy_to_only: result = deployed_to else: result = set(runs_on) | set(deployed_to) return list(sorted(result))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_cuthill_mckee'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'vertices'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'vertices_neighbours'}; {'id': '6', 'type': 'block', 'children': ['7', '25', '41', '49', '54', '62', '129']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'vertices_degrees'}; {'id': '10', 'type': 'dictionary_comprehension', 'children': ['11', '22']}, {'id': '11', 'type': 'pair', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'itervalues'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'vertices_neighbours'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'vertices'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'peripheral_vertex'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'parenthesized_expression', 'children': ['35'], 'value': '()'}, {'id': '35', 'type': 'lambda', 'children': ['36', '38']}; {'id': '36', 'type': 'lambda_parameters', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'vertices_degrees'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'visited'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'list', 'children': ['48'], 'value': '[peripheral_vertex]'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'peripheral_vertex'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cm_order'}; {'id': '52', 'type': 'list', 'children': ['53'], 'value': '[peripheral_vertex]'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'peripheral_vertex'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'previous_layer'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'list', 'children': ['61'], 'value': '[peripheral_vertex]'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'peripheral_vertex'}; {'id': '62', 'type': 'while_statement', 'children': ['63', '72']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '68'], 'value': '<'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cm_order'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'vertices'}; {'id': '72', 'type': 'block', 'children': ['73', '79', '92', '99', '106', '125']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'adjacent'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'vertex'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'previous_layer'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'adjacent'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'vertices_neighbours'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'vertex'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'adjacent'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'difference_update'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'visited'}, {'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': 'visited'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'adjacent'}; {'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': 'cm_order'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'adjacent'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '118', 'type': 'parenthesized_expression', 'children': ['119'], 'value': '()'}, {'id': '119', 'type': 'lambda', 'children': ['120', '122']}; {'id': '120', 'type': 'lambda_parameters', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'vertices_degrees'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'previous_layer'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'adjacent'}, {'id': '129', 'type': 'return_statement', 'children': ['130']}
def _cuthill_mckee(vertices, vertices_neighbours): vertices_degrees = {v: sum(itervalues(vertices_neighbours[v])) for v in vertices} peripheral_vertex = min(vertices, key=(lambda v: vertices_degrees[v])) visited = set([peripheral_vertex]) cm_order = [peripheral_vertex] previous_layer = set([peripheral_vertex]) while len(cm_order) < len(vertices): adjacent = set() for vertex in previous_layer: adjacent.update(vertices_neighbours[vertex]) adjacent.difference_update(visited) visited.update(adjacent) cm_order.extend(sorted(adjacent, key=(lambda v: vertices_degrees[v]))) previous_layer = adjacent return cm_order
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_csv'}, {'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': 'path'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '36', '49', '60', '68', '74']}, {'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': 'sort_sections'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'list', 'children': ['16', '17', '18', '19', '20', '21', '22'], 'value': "['Root', 'Contacts', 'Documentation', 'References', 'Resources', 'Citations', 'Schema']"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'Root'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'Contacts'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Documentation'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'References'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Resources'"}, {'id': '21', 'type': 'string', 'children': [], 'value': "'Citations'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'Schema'"}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'abstract'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '52', 'type': 'call', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'Root'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_or_new_term'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'Root.Modified'"}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'datetime_now'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort_by_term'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'write_csv'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'}
def write_csv(self, path=None): self.sort_sections(['Root', 'Contacts', 'Documentation', 'References', 'Resources', 'Citations', 'Schema']) if self.description: self.description = self.description if self.abstract: self.description = self.abstract t = self['Root'].get_or_new_term('Root.Modified') t.value = datetime_now() self.sort_by_term() return super().write_csv(str(path))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_functions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'BELAst'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bo'}, {'id': '9', 'type': 'block', 'children': ['10', '99', '118']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Function'}; {'id': '16', 'type': 'block', 'children': ['17', '24', '40', '46', '59']}, {'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': 'log'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': 'f"Validating: {ast.name}, {ast.function_type}, {ast.args}"'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'function_signatures'}, {'id': '27', 'type': 'subscript', 'children': ['28', '39']}; {'id': '28', 'type': 'subscript', 'children': ['29', '36']}, {'id': '29', 'type': 'subscript', 'children': ['30', '35']}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bo'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"functions"'}, {'id': '35', 'type': 'string', 'children': [], 'value': '"signatures"'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '39', 'type': 'string', 'children': [], 'value': '"signatures"'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'function_name'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ast'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'tuple_pattern', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'valid_function'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'check_function_args'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57', '58']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'function_signatures'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'function_name'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '62']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid_function'}; {'id': '62', 'type': 'block', 'children': ['63', '72', '93']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '", "'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bo'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'validation_messages'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'tuple', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '"ERROR"'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"Invalid BEL Statement function {} - problem with function signatures: {}"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '92']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'to_string'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'bo'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'parse_valid'}; {'id': '98', 'type': 'False', 'children': []}, {'id': '99', 'type': 'if_statement', 'children': ['100', '105']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"args"'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '111']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ast'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'validate_functions'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'bo'}; {'id': '118', 'type': 'return_statement', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'bo'}
def validate_functions(ast: BELAst, bo): if isinstance(ast, Function): log.debug(f"Validating: {ast.name}, {ast.function_type}, {ast.args}") function_signatures = bo.spec["functions"]["signatures"][ast.name]["signatures"] function_name = ast.name (valid_function, messages) = check_function_args( ast.args, function_signatures, function_name ) if not valid_function: message = ", ".join(messages) bo.validation_messages.append( ( "ERROR", "Invalid BEL Statement function {} - problem with function signatures: {}".format( ast.to_string(), message ), ) ) bo.parse_valid = False if hasattr(ast, "args"): for arg in ast.args: validate_functions(arg, bo) return bo
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_nanopub'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Mapping'}, {'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': 'str'}; {'id': '16', 'type': 'block', 'children': ['17', '21', '42', '63', '190', '194', '279', '286', '293', '297', '343', '350', '357', '374']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'hash_list'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '41']}; {'id': '28', 'type': 'attribute', 'children': ['29', '40']}, {'id': '29', 'type': 'call', 'children': ['30', '37']}; {'id': '30', 'type': 'attribute', 'children': ['31', '36']}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '34', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '35', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '39', 'type': 'string', 'children': [], 'value': '""'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'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': 'hash_list'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '62']}, {'id': '49', 'type': 'attribute', 'children': ['50', '61']}; {'id': '50', 'type': 'call', 'children': ['51', '58']}, {'id': '51', 'type': 'attribute', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'nanopub'}, {'id': '55', 'type': 'string', 'children': [], 'value': '"nanopub"'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"version"'}; {'id': '60', 'type': 'string', 'children': [], 'value': '""'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '75', '122', '156']}; {'id': '64', 'type': 'call', 'children': ['65', '72']}, {'id': '65', 'type': 'attribute', 'children': ['66', '71']}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'nanopub'}, {'id': '69', 'type': 'string', 'children': [], 'value': '"nanopub"'}; {'id': '70', 'type': 'string', 'children': [], 'value': '"citation"'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"database"'}; {'id': '74', 'type': 'False', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76', '99']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '98']}, {'id': '83', 'type': 'attribute', 'children': ['84', '97']}; {'id': '84', 'type': 'call', 'children': ['85', '94']}, {'id': '85', 'type': 'attribute', 'children': ['86', '93']}; {'id': '86', 'type': 'subscript', 'children': ['87', '92']}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '90', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '91', 'type': 'string', 'children': [], 'value': '"citation"'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"database"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '96', 'type': 'string', 'children': [], 'value': '""'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'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': 'hash_list'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '121']}; {'id': '106', 'type': 'attribute', 'children': ['107', '120']}, {'id': '107', 'type': 'call', 'children': ['108', '117']}; {'id': '108', 'type': 'attribute', 'children': ['109', '116']}, {'id': '109', 'type': 'subscript', 'children': ['110', '115']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'nanopub'}, {'id': '113', 'type': 'string', 'children': [], 'value': '"nanopub"'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"citation"'}, {'id': '115', 'type': 'string', 'children': [], 'value': '"database"'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': '"id"'}, {'id': '119', 'type': 'string', 'children': [], 'value': '""'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'elif_clause', 'children': ['123', '134']}, {'id': '123', 'type': 'call', 'children': ['124', '131']}; {'id': '124', 'type': 'attribute', 'children': ['125', '130']}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '129', 'type': 'string', 'children': [], 'value': '"citation"'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': '"uri"'}, {'id': '133', 'type': 'False', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'hash_list'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '155']}; {'id': '142', 'type': 'attribute', 'children': ['143', '154']}, {'id': '143', 'type': 'call', 'children': ['144', '151']}; {'id': '144', 'type': 'attribute', 'children': ['145', '150']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '148', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '149', 'type': 'string', 'children': [], 'value': '"citation"'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'string', 'children': [], 'value': '"uri"'}, {'id': '153', 'type': 'string', 'children': [], 'value': '""'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'elif_clause', 'children': ['157', '168']}, {'id': '157', 'type': 'call', 'children': ['158', '165']}; {'id': '158', 'type': 'attribute', 'children': ['159', '164']}, {'id': '159', 'type': 'subscript', 'children': ['160', '163']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"citation"'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"reference"'}, {'id': '167', 'type': 'False', 'children': []}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'hash_list'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '189']}; {'id': '176', 'type': 'attribute', 'children': ['177', '188']}, {'id': '177', 'type': 'call', 'children': ['178', '185']}; {'id': '178', 'type': 'attribute', 'children': ['179', '184']}, {'id': '179', 'type': 'subscript', 'children': ['180', '183']}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '182', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '183', 'type': 'string', 'children': [], 'value': '"citation"'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'string', 'children': [], 'value': '"reference"'}, {'id': '187', 'type': 'string', 'children': [], 'value': '""'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'assertions'}, {'id': '193', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '194', 'type': 'for_statement', 'children': ['195', '196', '201']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'assertion'}; {'id': '196', 'type': 'subscript', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'nanopub'}, {'id': '199', 'type': 'string', 'children': [], 'value': '"nanopub"'}; {'id': '200', 'type': 'string', 'children': [], 'value': '"assertions"'}, {'id': '201', 'type': 'block', 'children': ['202', '218', '234']}; {'id': '202', 'type': 'if_statement', 'children': ['203', '211']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '210'], 'value': 'is'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'assertion'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'string', 'children': [], 'value': '"relation"'}; {'id': '210', 'type': 'None', 'children': []}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'assertion'}; {'id': '216', 'type': 'string', 'children': [], 'value': '"relation"'}, {'id': '217', 'type': 'string', 'children': [], 'value': '""'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '227']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '226'], 'value': 'is'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'assertion'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'string', 'children': [], 'value': '"object"'}; {'id': '226', 'type': 'None', 'children': []}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '233']}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'assertion'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"object"'}, {'id': '233', 'type': 'string', 'children': [], 'value': '""'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'assertions'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '278']}, {'id': '241', 'type': 'attribute', 'children': ['242', '277']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'tuple', 'children': ['248', '255', '266']}; {'id': '248', 'type': 'call', 'children': ['249', '254']}, {'id': '249', 'type': 'attribute', 'children': ['250', '253']}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'assertion'}; {'id': '252', 'type': 'string', 'children': [], 'value': '"subject"'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '254', 'type': 'argument_list', 'children': []}, {'id': '255', 'type': 'call', 'children': ['256', '265']}; {'id': '256', 'type': 'attribute', 'children': ['257', '264']}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'assertion'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '263']}; {'id': '262', 'type': 'string', 'children': [], 'value': '"relation"'}, {'id': '263', 'type': 'string', 'children': [], 'value': '""'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '265', 'type': 'argument_list', 'children': []}; {'id': '266', 'type': 'call', 'children': ['267', '276']}, {'id': '267', 'type': 'attribute', 'children': ['268', '275']}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'assertion'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '274']}, {'id': '273', 'type': 'string', 'children': [], 'value': '"object"'}; {'id': '274', 'type': 'string', 'children': [], 'value': '""'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '276', 'type': 'argument_list', 'children': []}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '278', 'type': 'argument_list', 'children': []}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'assertions'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'assertions'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'assertions'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '296', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '297', 'type': 'for_statement', 'children': ['298', '299', '304']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'anno'}, {'id': '299', 'type': 'subscript', 'children': ['300', '303']}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'nanopub'}; {'id': '302', 'type': 'string', 'children': [], 'value': '"nanopub"'}, {'id': '303', 'type': 'string', 'children': [], 'value': '"annotations"'}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'call', 'children': ['312', '342']}; {'id': '312', 'type': 'attribute', 'children': ['313', '341']}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'tuple', 'children': ['319', '330']}, {'id': '319', 'type': 'call', 'children': ['320', '329']}; {'id': '320', 'type': 'attribute', 'children': ['321', '328']}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'anno'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327']}; {'id': '326', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '327', 'type': 'string', 'children': [], 'value': '""'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '329', 'type': 'argument_list', 'children': []}; {'id': '330', 'type': 'call', 'children': ['331', '340']}, {'id': '331', 'type': 'attribute', 'children': ['332', '339']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'anno'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '336', 'type': 'argument_list', 'children': ['337', '338']}, {'id': '337', 'type': 'string', 'children': [], 'value': '"id"'}; {'id': '338', 'type': 'string', 'children': [], 'value': '""'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '340', 'type': 'argument_list', 'children': []}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '342', 'type': 'argument_list', 'children': []}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'assignment', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '346', 'type': 'call', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '355', 'type': 'argument_list', 'children': ['356']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'annotations'}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'np_string'}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'list_comprehension', 'children': ['366', '371']}; {'id': '366', 'type': 'call', 'children': ['367', '370']}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '370', 'type': 'argument_list', 'children': []}, {'id': '371', 'type': 'for_in_clause', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'hash_list'}; {'id': '374', 'type': 'return_statement', 'children': ['375']}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'string', 'children': [], 'value': '"{:x}"'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'call', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'CityHash64'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'np_string'}
def hash_nanopub(nanopub: Mapping[str, Any]) -> str: hash_list = [] hash_list.append(nanopub["nanopub"]["type"].get("name", "").strip()) hash_list.append(nanopub["nanopub"]["type"].get("version", "").strip()) if nanopub["nanopub"]["citation"].get("database", False): hash_list.append( nanopub["nanopub"]["citation"]["database"].get("name", "").strip() ) hash_list.append( nanopub["nanopub"]["citation"]["database"].get("id", "").strip() ) elif nanopub["nanopub"]["citation"].get("uri", False): hash_list.append(nanopub["nanopub"]["citation"].get("uri", "").strip()) elif nanopub["nanopub"]["citation"].get("reference", False): hash_list.append(nanopub["nanopub"]["citation"].get("reference", "").strip()) assertions = [] for assertion in nanopub["nanopub"]["assertions"]: if assertion.get("relation") is None: assertion["relation"] = "" if assertion.get("object") is None: assertion["object"] = "" assertions.append( " ".join( ( assertion["subject"].strip(), assertion.get("relation", "").strip(), assertion.get("object", "").strip(), ) ).strip() ) assertions = sorted(assertions) hash_list.extend(assertions) annotations = [] for anno in nanopub["nanopub"]["annotations"]: annotations.append( " ".join((anno.get("type", "").strip(), anno.get("id", "").strip())).strip() ) annotations = sorted(annotations) hash_list.extend(annotations) np_string = " ".join([l.lower() for l in hash_list]) return "{:x}".format(CityHash64(np_string))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_listing'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '97', '117']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': 'func_entry'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '11', 'type': 'block', 'children': ['12', '24', '50', '70']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '18']}; {'id': '14', 'type': 'pattern_list', 'children': ['15', '16', '17']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'varargs'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'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': '_get_arg_spec'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '27', 'type': 'list_comprehension', 'children': ['28', '43', '46']}; {'id': '28', 'type': 'dictionary', 'children': ['29', '35', '40']}, {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '35', 'type': 'pair', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'optional'"}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'vararg'"}; {'id': '42', 'type': 'False', 'children': []}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '!='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'ctx'"}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'augmented_assignment', 'children': ['55', '56'], 'value': '+='}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '56', 'type': 'list', 'children': ['57'], 'value': "[{'name': str(varargs), 'optional': False, 'vararg': True}]"}, {'id': '57', 'type': 'dictionary', 'children': ['58', '64', '67']}; {'id': '58', 'type': 'pair', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '64', 'type': 'pair', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'optional'"}; {'id': '66', 'type': 'False', 'children': []}, {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'vararg'"}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'dictionary', 'children': ['72', '82', '94']}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'pair', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '84', 'type': 'call', 'children': ['85', '93']}, {'id': '85', 'type': 'attribute', 'children': ['86', '92']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': '__doc__'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'params'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'listing'}; {'id': '100', 'type': 'list_comprehension', 'children': ['101', '106']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'func_entry'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'f_name'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '110']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'f_name'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '110', 'type': 'call', 'children': ['111', '116']}, {'id': '111', 'type': 'attribute', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_functions'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'listing'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '124', 'type': 'lambda', 'children': ['125', '127']}, {'id': '125', 'type': 'lambda_parameters', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'name'"}
def build_listing(self): def func_entry(name, func): args, varargs, defaults = self._get_arg_spec(func) params = [{'name': str(a), 'optional': a in defaults, 'vararg': False} for a in args if a != 'ctx'] if varargs: params += [{'name': str(varargs), 'optional': False, 'vararg': True}] return {'name': str(name.upper()), 'description': str(func.__doc__).strip(), 'params': params} listing = [func_entry(f_name, f) for f_name, f in self._functions.items()] return sorted(listing, key=lambda l: l['name'])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_url_qsl'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'raw_url'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '25']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'parsed_url'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'urlparse'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'raw_url'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'qsl'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'parse_qsl'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parsed_url'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_join_url'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'parsed_url'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'qsl'}; {'id': '36', 'type': 'dictionary_splat', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def sort_url_qsl(cls, raw_url, **kwargs): parsed_url = urlparse(raw_url) qsl = parse_qsl(parsed_url.query) return cls._join_url(parsed_url, sorted(qsl, **kwargs))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sorted_series_files'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'startpath'}, {'id': '7', 'type': 'string', 'children': [], 'value': '""'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'series_number'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'return_files_with_info'}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'id': '16', 'type': 'string', 'children': [], 'value': '"SliceLocation"'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'return_files'}, {'id': '19', 'type': 'True', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'remove_doubled_slice_locations'}; {'id': '22', 'type': 'True', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '33', '52', '62', '74', '86', '90', '114', '118', '128', '138', '173']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}, {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'files_with_info'}, {'id': '31', 'type': 'slice', 'children': ['32']}; {'id': '32', 'type': 'colon', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'series_number'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}, {'id': '41', 'type': 'list_comprehension', 'children': ['42', '43', '46']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'SeriesNumber'"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'series_number'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sort_list_of_dicts'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_keys'}; {'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': 'logger'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '+'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'SeriesNumber: '"}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'series_number'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'remove_doubled_slice_locations'}; {'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': 'dcmdir'}; {'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': '_remove_doubled_slice_locations'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'filelist'}, {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'onefile'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'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': 'filelist'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '106']}, {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108', '111']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'startpath'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'dirpath'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'onefile'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '117', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'return_files'}; {'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': 'retval'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'filelist'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'return_files_with_info'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dcmdir'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '145', '150', '164']}, {'id': '139', 'type': 'comparison_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': 'retval'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'elif_clause', 'children': ['151', '157']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '156'], 'value': '=='}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'retval'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'retval'}, {'id': '173', 'type': 'return_statement', 'children': ['174']}
def get_sorted_series_files(self, startpath="", series_number=None, return_files_with_info=False, sort_keys="SliceLocation", return_files=True, remove_doubled_slice_locations=True): dcmdir = self.files_with_info[:] if series_number is not None: dcmdir = [ line for line in dcmdir if line['SeriesNumber'] == series_number ] dcmdir = sort_list_of_dicts(dcmdir, keys=sort_keys) logger.debug('SeriesNumber: ' + str(series_number)) if remove_doubled_slice_locations: dcmdir = self._remove_doubled_slice_locations(dcmdir) filelist = [] for onefile in dcmdir: filelist.append(os.path.join(startpath, self.dirpath, onefile['filename'])) retval = [] if return_files: retval.append(filelist) if return_files_with_info: retval.append(dcmdir) if len(retval) == 0: retval = None elif len(retval) == 1: retval = retval[0] else: retval = tuple(retval) return retval
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'guess_interval'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nums'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'accuracy'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '29', '41', '65', '77', '84', '95']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'list_comprehension', 'children': ['22', '26']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'nums'}, {'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': 'nums'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '54']}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '51'], 'value': '-'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'nums'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '64'], 'value': '-'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '68', 'type': 'list_comprehension', 'children': ['69', '70', '73']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'diffs'}, {'id': '73', 'type': 'if_clause', 'children': ['74']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '>='}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'accuracy'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sorted_diff'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted_diff'}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '94'], 'value': '//'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '95', 'type': 'return_statement', 'children': ['96']}
def guess_interval(nums, accuracy=0): if not nums: return 0 nums = sorted([int(i) for i in nums]) if len(nums) == 1: return nums[0] diffs = [nums[i + 1] - nums[i] for i in range(len(nums) - 1)] diffs = [item for item in diffs if item >= accuracy] sorted_diff = sorted(diffs) result = sorted_diff[len(diffs) // 2] return result
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_list_of_dicts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'lst_of_dct'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_args'}, {'id': '11', 'type': 'block', 'children': ['12', '25', '58']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '19']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '18'], 'value': '!='}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '23', 'type': 'list', 'children': ['24'], 'value': '[keys]'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'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': 'lst_of_dct'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '53', '56']}, {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'lambda', 'children': ['34', '36']}; {'id': '34', 'type': 'lambda_parameters', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '50']}, {'id': '37', 'type': 'parenthesized_expression', 'children': ['38'], 'value': '()'}; {'id': '38', 'type': 'conditional_expression', 'children': ['39', '44', '47'], 'value': 'if'}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '47', 'type': 'tuple', 'children': ['48', '49']}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '56', 'type': 'dictionary_splat', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort_args'}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'lst_of_dct'}
def sort_list_of_dicts(lst_of_dct, keys, reverse=False, **sort_args): if type(keys) != list: keys = [keys] lst_of_dct.sort(key=lambda x: [((False, x[key]) if key in x else (True, 0)) for key in keys], reverse=reverse, **sort_args) return lst_of_dct
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parallel_deblur'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'inputs'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pos_ref_db_fp'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'neg_ref_dp_fp'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'jobs_to_start'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'block', 'children': ['12', '21', '33', '42', '46', '50', '83', '109', '135', '144', '153', '162', '173', '180']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '%'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'parallel deblur started for %d inputs'"}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'inputs'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'remove_param_list'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39', '40', '41'], 'value': "['-O', '--jobs-to-start', '--seqs-fp',\n '--pos-ref-db-fp', '--neg-ref-db-fp']"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'-O'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'--jobs-to-start'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'--seqs-fp'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'--pos-ref-db-fp'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'--neg-ref-db-fp'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'skipnext'}, {'id': '45', 'type': 'False', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'newparams'}, {'id': '49', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '57']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'carg'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '54', 'type': 'slice', 'children': ['55', '56']}, {'id': '55', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '56', 'type': 'colon', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58', '66', '76']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'skipnext'}; {'id': '60', 'type': 'block', 'children': ['61', '65']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'skipnext'}; {'id': '64', 'type': 'False', 'children': []}, {'id': '65', 'type': 'continue_statement', 'children': []}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'carg'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'remove_param_list'}; {'id': '70', 'type': 'block', 'children': ['71', '75']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'skipnext'}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'continue_statement', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'newparams'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'carg'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pos_ref_db_fp'}, {'id': '85', 'type': 'block', 'children': ['86', '95', '102']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_pos_ref_db_fp'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': "','"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pos_ref_db_fp'}, {'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': 'newparams'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'--pos-ref-db-fp'"}; {'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': 'newparams'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'new_pos_ref_db_fp'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'neg_ref_dp_fp'}, {'id': '111', 'type': 'block', 'children': ['112', '121', '128']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'new_neg_ref_db_fp'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'string', 'children': [], 'value': "','"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'neg_ref_dp_fp'}, {'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': 'newparams'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'--neg-ref-db-fp'"}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'newparams'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'new_neg_ref_db_fp'}, {'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': 'logger'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'ready for functor %s'"}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'newparams'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'functor'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151', '152']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'run_functor'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'deblur_system_call'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'newparams'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'ready for pool %d jobs'"}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'jobs_to_start'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'Pool'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'processes'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'jobs_to_start'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'almost running...'"}; {'id': '180', 'type': 'for_statement', 'children': ['181', '185', '192']}, {'id': '181', 'type': 'pattern_list', 'children': ['182', '183', '184']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'es'}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'functor'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'inputs'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'if_statement', 'children': ['194', '197']}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '!='}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'raise_statement', 'children': ['199']}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '%'}, {'id': '203', 'type': 'string', 'children': [], 'value': '"stdout: %s\\nstderr: %s\\nexit: %d"'}; {'id': '204', 'type': 'tuple', 'children': ['205', '206', '207']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'stderr'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'es'}
def parallel_deblur(inputs, params, pos_ref_db_fp, neg_ref_dp_fp, jobs_to_start=1): logger = logging.getLogger(__name__) logger.info('parallel deblur started for %d inputs' % len(inputs)) remove_param_list = ['-O', '--jobs-to-start', '--seqs-fp', '--pos-ref-db-fp', '--neg-ref-db-fp'] skipnext = False newparams = [] for carg in params[2:]: if skipnext: skipnext = False continue if carg in remove_param_list: skipnext = True continue newparams.append(carg) if pos_ref_db_fp: new_pos_ref_db_fp = ','.join(pos_ref_db_fp) newparams.append('--pos-ref-db-fp') newparams.append(new_pos_ref_db_fp) if neg_ref_dp_fp: new_neg_ref_db_fp = ','.join(neg_ref_dp_fp) newparams.append('--neg-ref-db-fp') newparams.append(new_neg_ref_db_fp) logger.debug('ready for functor %s' % newparams) functor = partial(run_functor, deblur_system_call, newparams) logger.debug('ready for pool %d jobs' % jobs_to_start) pool = mp.Pool(processes=jobs_to_start) logger.debug('almost running...') for stdout, stderr, es in pool.map(functor, inputs): if es != 0: raise RuntimeError("stdout: %s\nstderr: %s\nexit: %d" % (stdout, stderr, es))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_index_sortmerna'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '29', '33', '164']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'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': 'logger'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '26'], 'value': '%'}, {'id': '23', 'type': 'concatenated_string', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'build_index_sortmerna files %s to'"}, {'id': '25', 'type': 'string', 'children': [], 'value': "' dir %s'"}; {'id': '26', 'type': 'tuple', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'all_db'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '36', 'type': 'block', 'children': ['37', '46', '55', '63', '74', '87', '97', '148', '157']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '42']}, {'id': '39', 'type': 'pattern_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fasta_dir'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'index_basename'}, {'id': '49', 'type': 'subscript', 'children': ['50', '54']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'splitext'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'db_output'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'index_basename'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '%'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'processing file %s into location %s'"}, {'id': '71', 'type': 'tuple', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'db_output'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '77', 'type': 'list', 'children': ['78', '79', '80', '85', '86'], 'value': "['indexdb_rna', '--ref', '%s,%s' %\n (db, db_output), '--tmpdir', working_dir]"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'indexdb_rna'"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'--ref'"}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '%'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'%s,%s'"}; {'id': '82', 'type': 'tuple', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'db_output'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'--tmpdir'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '93']}, {'id': '89', 'type': 'pattern_list', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sout'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'serr'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_system_call'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '102']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '=='}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'block', 'children': ['103', '116', '125', '134', '141']}, {'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': 'logger'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '%'}; {'id': '110', 'type': 'concatenated_string', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'Problem running indexdb_rna on file %s to dir %s. '"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'database not indexed'"}, {'id': '113', 'type': 'tuple', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'db_output'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'stdout: %s'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sout'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '%'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'stderr: %s'"}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'serr'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'execution halted'"}, {'id': '141', 'type': 'raise_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'Cannot index database file %s'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '%'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'file %s indexed'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'db'}, {'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': 'all_db'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'db_output'}; {'id': '164', 'type': 'return_statement', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'all_db'}
def build_index_sortmerna(ref_fp, working_dir): logger = logging.getLogger(__name__) logger.info('build_index_sortmerna files %s to' ' dir %s' % (ref_fp, working_dir)) all_db = [] for db in ref_fp: fasta_dir, fasta_filename = split(db) index_basename = splitext(fasta_filename)[0] db_output = join(working_dir, index_basename) logger.debug('processing file %s into location %s' % (db, db_output)) params = ['indexdb_rna', '--ref', '%s,%s' % (db, db_output), '--tmpdir', working_dir] sout, serr, res = _system_call(params) if not res == 0: logger.error('Problem running indexdb_rna on file %s to dir %s. ' 'database not indexed' % (db, db_output)) logger.debug('stdout: %s' % sout) logger.debug('stderr: %s' % serr) logger.critical('execution halted') raise RuntimeError('Cannot index database file %s' % db) logger.debug('file %s indexed' % db) all_db.append(db_output) return all_db
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_artifacts_from_biom_table'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'table_filename'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '31', '38', '70', '86', '99', '112', '126', '135', '142', '163', '168', '176', '182', '191', '199', '205', '218', '223', '231', '237', '246', '254', '260', '267']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'getting 16s sequences from the biom table'"}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '44']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'clean_fp'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'num_seqs_left'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'tmp_files'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'remove_artifacts_seqs'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49', '52', '55', '58', '61', '64', '67']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'negate'}, {'id': '57', 'type': 'False', 'children': []}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'clean_fp'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75', '84']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '%'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"No clean sequences in %s"'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tmp_files'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '91', 'type': 'argument_list', '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': "'removed artifacts from sequences input %s'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "' to output %s'"}; {'id': '96', 'type': 'tuple', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'fasta_filename'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'clean_fp'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'good_seqs'}; {'id': '102', 'type': 'set_comprehension', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '104', 'type': 'for_in_clause', 'children': ['105', '108']}, {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sequence_generator'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'clean_fp'}; {'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': 'logger'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '%'}, {'id': '119', 'type': 'concatenated_string', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'loaded %d sequences from cleaned biom table'"}, {'id': '121', 'type': 'string', 'children': [], 'value': "' fasta file'"}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'good_seqs'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'loading biom table %s'"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'table_filename'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'load_table'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'table_filename'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'artifact_table'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '154', '157', '160']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'good_seqs'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'observation'"}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '159', 'type': 'False', 'children': []}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '162', 'type': 'True', 'children': []}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'filter_minreads_samples_from_table'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'artifact_table'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'output_nomatch_fp'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}, {'id': '175', 'type': 'string', 'children': [], 'value': "'reference-non-hit.biom'"}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'write_biom_table'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'artifact_table'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'output_nomatch_fp'}; {'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': 'logger'}; {'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': "'wrote artifact only filtered biom table to %s'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'output_nomatch_fp'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'output_nomatch_fasta_fp'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'reference-non-hit.seqs.fa'"}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'fasta_from_biom'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'artifact_table'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'output_nomatch_fasta_fp'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '215']}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'good_seqs'}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '217', 'type': 'string', 'children': [], 'value': "'observation'"}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'filter_minreads_samples_from_table'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'output_fp'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'reference-hit.biom'"}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'write_biom_table'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'output_fp'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '%'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'wrote 16s filtered biom table to %s'"}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'output_fp'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'output_match_fasta_fp'}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'biom_table_dir'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'reference-hit.seqs.fa'"}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'fasta_from_biom'}, {'id': '257', 'type': 'argument_list', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'output_match_fasta_fp'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'tmp_files'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'clean_fp'}, {'id': '267', 'type': 'return_statement', 'children': ['268']}
def remove_artifacts_from_biom_table(table_filename, fasta_filename, ref_fp, biom_table_dir, ref_db_fp, threads=1, verbose=False, sim_thresh=None, coverage_thresh=None): logger = logging.getLogger(__name__) logger.info('getting 16s sequences from the biom table') clean_fp, num_seqs_left, tmp_files = remove_artifacts_seqs(fasta_filename, ref_fp, working_dir=biom_table_dir, ref_db_fp=ref_db_fp, negate=False, threads=threads, verbose=verbose, sim_thresh=sim_thresh, coverage_thresh=coverage_thresh) if clean_fp is None: logger.warn("No clean sequences in %s" % fasta_filename) return tmp_files logger.debug('removed artifacts from sequences input %s' ' to output %s' % (fasta_filename, clean_fp)) good_seqs = {s for _, s in sequence_generator(clean_fp)} logger.debug('loaded %d sequences from cleaned biom table' ' fasta file' % len(good_seqs)) logger.debug('loading biom table %s' % table_filename) table = load_table(table_filename) artifact_table = table.filter(list(good_seqs), axis='observation', inplace=False, invert=True) filter_minreads_samples_from_table(artifact_table) output_nomatch_fp = join(biom_table_dir, 'reference-non-hit.biom') write_biom_table(artifact_table, output_nomatch_fp) logger.info('wrote artifact only filtered biom table to %s' % output_nomatch_fp) output_nomatch_fasta_fp = join(biom_table_dir, 'reference-non-hit.seqs.fa') fasta_from_biom(artifact_table, output_nomatch_fasta_fp) table.filter(list(good_seqs), axis='observation') filter_minreads_samples_from_table(table) output_fp = join(biom_table_dir, 'reference-hit.biom') write_biom_table(table, output_fp) logger.info('wrote 16s filtered biom table to %s' % output_fp) output_match_fasta_fp = join(biom_table_dir, 'reference-hit.seqs.fa') fasta_from_biom(table, output_match_fasta_fp) tmp_files.append(clean_fp) return tmp_files
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_artifacts_seqs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'negate'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '16', 'type': 'False', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '33', '42', '66', '88', '110', '114', '127', '140', '146', '335', '358', '362', '366', '370', '432', '446']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'getLogger'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'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']}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '%'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'remove_artifacts_seqs file %s'"}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '51']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '50'], 'value': '=='}; {'id': '44', 'type': 'attribute', 'children': ['45', '49']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'st_size'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '51', 'type': 'block', 'children': ['52', '61']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'file %s has size 0, continuing'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'expression_list', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'if_statement', 'children': ['72', '73', '80']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'negate'}, {'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': 'coverage_thresh'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '*'}; {'id': '78', 'type': 'float', 'children': [], 'value': '0.95'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '*'}; {'id': '86', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'if_statement', 'children': ['94', '95', '102']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'negate'}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '*'}; {'id': '100', 'type': 'float', 'children': [], 'value': '0.95'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '*'}; {'id': '108', 'type': 'float', 'children': [], 'value': '0.65'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'bitscore_thresh'}, {'id': '113', 'type': 'float', 'children': [], 'value': '0.65'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'output_fp'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '%'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"%s.no_artifacts"'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'blast_output'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '%'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'%s.sortmerna'"}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'aligned_seq_ids'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'for_statement', 'children': ['147', '150', '154']}, {'id': '147', 'type': 'pattern_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '154', 'type': 'block', 'children': ['155', '170', '195', '205', '243', '249']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'running on ref_fp %s working dir %s refdb_fp %s seqs %s'"}, {'id': '163', 'type': 'tuple', 'children': ['164', '165', '166', '169']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '173', 'type': 'list', 'children': ['174', '175', '176', '177', '178', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194'], 'value': "['sortmerna', '--reads', seqs_fp, '--ref', '%s,%s' %\n (db, ref_db_fp[i]),\n '--aligned', blast_output, '--blast', '3', '--best', '1',\n '--print_all_reads', '-v', '-e', '100']"}; {'id': '174', 'type': 'string', 'children': [], 'value': "'sortmerna'"}, {'id': '175', 'type': 'string', 'children': [], 'value': "'--reads'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'--ref'"}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '%'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'%s,%s'"}; {'id': '180', 'type': 'tuple', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'--aligned'"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'blast_output'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'--blast'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "'3'"}, {'id': '189', 'type': 'string', 'children': [], 'value': "'--best'"}; {'id': '190', 'type': 'string', 'children': [], 'value': "'1'"}, {'id': '191', 'type': 'string', 'children': [], 'value': "'--print_all_reads'"}; {'id': '192', 'type': 'string', 'children': [], 'value': "'-v'"}, {'id': '193', 'type': 'string', 'children': [], 'value': "'-e'"}; {'id': '194', 'type': 'string', 'children': [], 'value': "'100'"}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '201']}, {'id': '197', 'type': 'pattern_list', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'sout'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'serr'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': '_system_call'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '205', 'type': 'if_statement', 'children': ['206', '210']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': '=='}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'block', 'children': ['211', '220', '229', '238']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'sortmerna error on file %s'"}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'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': 'logger'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '%'}, {'id': '227', 'type': 'string', 'children': [], 'value': "'stdout : %s'"}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'sout'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '%'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'stderr : %s'"}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'serr'}; {'id': '238', 'type': 'return_statement', 'children': ['239']}, {'id': '239', 'type': 'expression_list', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'output_fp'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '242', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'blast_output_filename'}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '%'}, {'id': '247', 'type': 'string', 'children': [], 'value': "'%s.blast'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'blast_output'}, {'id': '249', 'type': 'with_statement', 'children': ['250', '260']}; {'id': '250', 'type': 'with_clause', 'children': ['251']}, {'id': '251', 'type': 'with_item', 'children': ['252']}; {'id': '252', 'type': 'as_pattern', 'children': ['253', '258']}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'blast_output_filename'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '258', 'type': 'as_pattern_target', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'bfl'}; {'id': '260', 'type': 'block', 'children': ['261']}, {'id': '261', 'type': 'for_statement', 'children': ['262', '263', '264']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'bfl'}; {'id': '264', 'type': 'block', 'children': ['265', '278', '286']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '268', 'type': 'call', 'children': ['269', '276']}, {'id': '269', 'type': 'attribute', 'children': ['270', '275']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '274', 'type': 'argument_list', 'children': []}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '278', 'type': 'if_statement', 'children': ['279', '284']}, {'id': '279', 'type': 'comparison_operator', 'children': ['280', '283'], 'value': '=='}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '284', 'type': 'block', 'children': ['285']}, {'id': '285', 'type': 'continue_statement', 'children': []}; {'id': '286', 'type': 'if_statement', 'children': ['287', '325']}, {'id': '287', 'type': 'boolean_operator', 'children': ['288', '308', '309'], 'value': 'and'}; {'id': '288', 'type': 'boolean_operator', 'children': ['289', '298', '299'], 'value': 'and'}, {'id': '289', 'type': 'parenthesized_expression', 'children': ['290'], 'value': '()'}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '297'], 'value': '>='}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}; {'id': '298', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '299', 'type': 'parenthesized_expression', 'children': ['300'], 'value': '()'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '307'], 'value': '>='}, {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '306', 'type': 'integer', 'children': [], 'value': '13'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}; {'id': '308', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '309', 'type': 'parenthesized_expression', 'children': ['310'], 'value': '()'}; {'id': '310', 'type': 'comparison_operator', 'children': ['311', '317'], 'value': '>='}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'subscript', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '316', 'type': 'integer', 'children': [], 'value': '11'}, {'id': '317', 'type': 'binary_operator', 'children': ['318', '319'], 'value': '*'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'bitscore_thresh'}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '324', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '325', 'type': 'block', 'children': ['326']}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'aligned_seq_ids'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'subscript', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '334', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '335', 'type': 'if_statement', 'children': ['336', '337', '347']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'negate'}, {'id': '337', 'type': 'block', 'children': ['338']}; {'id': '338', 'type': 'function_definition', 'children': ['339', '340', '342']}, {'id': '339', 'type': 'function_name', 'children': [], 'value': 'op'}; {'id': '340', 'type': 'parameters', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '342', 'type': 'block', 'children': ['343']}, {'id': '343', 'type': 'return_statement', 'children': ['344']}; {'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': 'not'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'aligned_seq_ids'}, {'id': '347', 'type': 'else_clause', 'children': ['348']}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'function_definition', 'children': ['350', '351', '353']}; {'id': '350', 'type': 'function_name', 'children': [], 'value': 'op'}, {'id': '351', 'type': 'parameters', 'children': ['352']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'return_statement', 'children': ['355']}, {'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': 'in'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'aligned_seq_ids'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}, {'id': '359', 'type': 'assignment', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'totalseqs'}, {'id': '361', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'assignment', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'okseqs'}, {'id': '365', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'assignment', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'badseqs'}, {'id': '369', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '370', 'type': 'with_statement', 'children': ['371', '381']}, {'id': '371', 'type': 'with_clause', 'children': ['372']}; {'id': '372', 'type': 'with_item', 'children': ['373']}, {'id': '373', 'type': 'as_pattern', 'children': ['374', '379']}; {'id': '374', 'type': 'call', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '376', 'type': 'argument_list', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'output_fp'}; {'id': '378', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '379', 'type': 'as_pattern_target', 'children': ['380']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'out_f'}, {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'for_statement', 'children': ['383', '386', '390']}, {'id': '383', 'type': 'pattern_list', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '386', 'type': 'call', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'sequence_generator'}; {'id': '388', 'type': 'argument_list', 'children': ['389']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '390', 'type': 'block', 'children': ['391', '395', '405']}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'augmented_assignment', 'children': ['393', '394'], 'value': '+='}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'totalseqs'}; {'id': '394', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '395', 'type': 'expression_statement', 'children': ['396']}; {'id': '396', 'type': 'assignment', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '398', 'type': 'subscript', 'children': ['399', '404']}, {'id': '399', 'type': 'call', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '403', 'type': 'argument_list', 'children': []}; {'id': '404', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '405', 'type': 'if_statement', 'children': ['406', '410', '426']}; {'id': '406', 'type': 'call', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '410', 'type': 'block', 'children': ['411', '422']}, {'id': '411', 'type': 'expression_statement', 'children': ['412']}; {'id': '412', 'type': 'call', 'children': ['413', '416']}, {'id': '413', 'type': 'attribute', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'out_f'}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '416', 'type': 'argument_list', 'children': ['417']}, {'id': '417', 'type': 'binary_operator', 'children': ['418', '419'], 'value': '%'}; {'id': '418', 'type': 'string', 'children': [], 'value': '">%s\\n%s\\n"'}, {'id': '419', 'type': 'tuple', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '422', 'type': 'expression_statement', 'children': ['423']}, {'id': '423', 'type': 'augmented_assignment', 'children': ['424', '425'], 'value': '+='}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'okseqs'}, {'id': '425', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '426', 'type': 'else_clause', 'children': ['427']}, {'id': '427', 'type': 'block', 'children': ['428']}; {'id': '428', 'type': 'expression_statement', 'children': ['429']}, {'id': '429', 'type': 'augmented_assignment', 'children': ['430', '431'], 'value': '+='}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'badseqs'}, {'id': '431', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '432', 'type': 'expression_statement', 'children': ['433']}, {'id': '433', 'type': 'call', 'children': ['434', '437']}; {'id': '434', 'type': 'attribute', 'children': ['435', '436']}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '437', 'type': 'argument_list', 'children': ['438']}; {'id': '438', 'type': 'binary_operator', 'children': ['439', '442'], 'value': '%'}, {'id': '439', 'type': 'concatenated_string', 'children': ['440', '441']}; {'id': '440', 'type': 'string', 'children': [], 'value': "'total sequences %d, passing sequences %d, '"}, {'id': '441', 'type': 'string', 'children': [], 'value': "'failing sequences %d'"}; {'id': '442', 'type': 'tuple', 'children': ['443', '444', '445']}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'totalseqs'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'okseqs'}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'badseqs'}; {'id': '446', 'type': 'return_statement', 'children': ['447']}, {'id': '447', 'type': 'expression_list', 'children': ['448', '449', '450']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'output_fp'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'okseqs'}; {'id': '450', 'type': 'list', 'children': ['451'], 'value': '[blast_output_filename]'}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'blast_output_filename'}
def remove_artifacts_seqs(seqs_fp, ref_fp, working_dir, ref_db_fp, negate=False, threads=1, verbose=False, sim_thresh=None, coverage_thresh=None): logger = logging.getLogger(__name__) logger.info('remove_artifacts_seqs file %s' % seqs_fp) if stat(seqs_fp).st_size == 0: logger.warn('file %s has size 0, continuing' % seqs_fp) return None, 0, [] if coverage_thresh is None: if negate: coverage_thresh = 0.95 * 100 else: coverage_thresh = 0.5 * 100 if sim_thresh is None: if negate: sim_thresh = 0.95 * 100 else: sim_thresh = 0.65 * 100 bitscore_thresh = 0.65 output_fp = join(working_dir, "%s.no_artifacts" % basename(seqs_fp)) blast_output = join(working_dir, '%s.sortmerna' % basename(seqs_fp)) aligned_seq_ids = set() for i, db in enumerate(ref_fp): logger.debug('running on ref_fp %s working dir %s refdb_fp %s seqs %s' % (db, working_dir, ref_db_fp[i], seqs_fp)) params = ['sortmerna', '--reads', seqs_fp, '--ref', '%s,%s' % (db, ref_db_fp[i]), '--aligned', blast_output, '--blast', '3', '--best', '1', '--print_all_reads', '-v', '-e', '100'] sout, serr, res = _system_call(params) if not res == 0: logger.error('sortmerna error on file %s' % seqs_fp) logger.error('stdout : %s' % sout) logger.error('stderr : %s' % serr) return output_fp, 0, [] blast_output_filename = '%s.blast' % blast_output with open(blast_output_filename, 'r') as bfl: for line in bfl: line = line.strip().split('\t') if line[1] == '*': continue if (float(line[2]) >= sim_thresh) and \ (float(line[13]) >= coverage_thresh) and \ (float(line[11]) >= bitscore_thresh * len(line[0])): aligned_seq_ids.add(line[0]) if negate: def op(x): return x not in aligned_seq_ids else: def op(x): return x in aligned_seq_ids totalseqs = 0 okseqs = 0 badseqs = 0 with open(output_fp, 'w') as out_f: for label, seq in sequence_generator(seqs_fp): totalseqs += 1 label = label.split()[0] if op(label): out_f.write(">%s\n%s\n" % (label, seq)) okseqs += 1 else: badseqs += 1 logger.info('total sequences %d, passing sequences %d, ' 'failing sequences %d' % (totalseqs, okseqs, badseqs)) return output_fp, okseqs, [blast_output_filename]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'launch_workflow'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mean_error'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'error_dist'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'indel_prob'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'indel_max'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'trim_length'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'left_trim_length'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'min_size'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'threads_per_sample'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'coverage_thresh'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '34', '41', '50', '63', '106', '119', '135', '165', '188', '280', '293', '376', '387', '394']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'--------------------------------------------------------'"}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'launch_workflow for file %s'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'output_trim_fp'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '%'}; {'id': '58', 'type': 'string', 'children': [], 'value': '"%s.trim"'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '63', 'type': 'with_statement', 'children': ['64', '74']}; {'id': '64', 'type': 'with_clause', 'children': ['65']}, {'id': '65', 'type': 'with_item', 'children': ['66']}; {'id': '66', 'type': 'as_pattern', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'output_trim_fp'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '72', 'type': 'as_pattern_target', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'out_f'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'for_statement', 'children': ['76', '79', '94']}; {'id': '76', 'type': 'pattern_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'seq'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'trim_seqs'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '88', '91']}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'input_seqs'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sequence_generator'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'trim_len'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'trim_length'}, {'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'left_trim_len'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'left_trim_length'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'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': 'out_f'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'}; {'id': '102', 'type': 'string', 'children': [], 'value': '">%s\\n%s\\n"'}, {'id': '103', 'type': 'tuple', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'output_derep_fp'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '%'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"%s.derep"'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'output_trim_fp'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'dereplicate_seqs'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '126', '129', '132']}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'output_trim_fp'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'output_fp'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'output_derep_fp'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'min_size'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'min_size'}; {'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'threads_per_sample'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '141']}, {'id': '137', 'type': 'pattern_list', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'output_artif_fp'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'num_seqs_left'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'remove_artifacts_seqs'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '147', '150', '153', '156', '159', '162']}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'output_derep_fp'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ref_fp'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ref_db_fp'}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'negate'}; {'id': '158', 'type': 'True', 'children': []}, {'id': '159', 'type': 'keyword_argument', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'threads_per_sample'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sim_thresh'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '168']}; {'id': '166', 'type': 'not_operator', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'output_artif_fp'}; {'id': '168', 'type': 'block', 'children': ['169', '179', '186']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '178']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'Problem removing artifacts from file %s'"}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'string', 'children': [], 'value': "'remove artifacts failed, aborting'"}; {'id': '186', 'type': 'return_statement', 'children': ['187']}, {'id': '187', 'type': 'None', 'children': []}; {'id': '188', 'type': 'if_statement', 'children': ['189', '192', '243', '252']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '>'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'num_seqs_left'}, {'id': '191', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '192', 'type': 'block', 'children': ['193', '206', '218']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'}, {'id': '201', 'type': 'string', 'children': [], 'value': '"%s.msa"'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'output_artif_fp'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'alignment'}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'multiple_sequence_alignment'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '215']}; {'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'output_artif_fp'}, {'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'threads'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'threads_per_sample'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '221']}, {'id': '219', 'type': 'not_operator', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'alignment'}, {'id': '221', 'type': 'block', 'children': ['222', '234', '241']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '233']}; {'id': '228', 'type': 'binary_operator', 'children': ['229', '232'], 'value': '%'}, {'id': '229', 'type': 'concatenated_string', 'children': ['230', '231']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'Problem performing multiple sequence alignment '"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'on file %s'"}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'msa failed. aborting'"}, {'id': '241', 'type': 'return_statement', 'children': ['242']}; {'id': '242', 'type': 'None', 'children': []}, {'id': '243', 'type': 'elif_clause', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'num_seqs_left'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'output_artif_fp'}; {'id': '252', 'type': 'else_clause', 'children': ['253']}, {'id': '253', 'type': 'block', 'children': ['254', '263', '271', '278']}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'err_msg'}, {'id': '257', 'type': 'parenthesized_expression', 'children': ['258'], 'value': '()'}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '262'], 'value': '%'}, {'id': '259', 'type': 'concatenated_string', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'No sequences left after artifact removal in '"}, {'id': '261', 'type': 'string', 'children': [], 'value': "'file %s'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'seqs_fp'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'err_msg'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}, {'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': 'logger'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'err_msg'}; {'id': '278', 'type': 'return_statement', 'children': ['279']}, {'id': '279', 'type': 'None', 'children': []}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'output_deblur_fp'}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '285', 'type': 'argument_list', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'working_dir'}, {'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '%'}; {'id': '288', 'type': 'string', 'children': [], 'value': '"%s.deblur"'}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}, {'id': '293', 'type': 'with_statement', 'children': ['294', '304']}; {'id': '294', 'type': 'with_clause', 'children': ['295']}, {'id': '295', 'type': 'with_item', 'children': ['296']}; {'id': '296', 'type': 'as_pattern', 'children': ['297', '302']}, {'id': '297', 'type': 'call', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '299', 'type': 'argument_list', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'output_deblur_fp'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '302', 'type': 'as_pattern_target', 'children': ['303']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '304', 'type': 'block', 'children': ['305', '319', '347']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'seqs'}; {'id': '308', 'type': 'call', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'deblur'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '315', '316', '317', '318']}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'sequence_generator'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'mean_error'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'error_dist'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'indel_prob'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'indel_max'}, {'id': '319', 'type': 'if_statement', 'children': ['320', '323']}; {'id': '320', 'type': 'comparison_operator', 'children': ['321', '322'], 'value': 'is'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'seqs'}; {'id': '322', 'type': 'None', 'children': []}, {'id': '323', 'type': 'block', 'children': ['324', '336', '345']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '329', 'type': 'argument_list', 'children': ['330', '335']}; {'id': '330', 'type': 'binary_operator', 'children': ['331', '334'], 'value': '%'}, {'id': '331', 'type': 'concatenated_string', 'children': ['332', '333']}; {'id': '332', 'type': 'string', 'children': [], 'value': "'multiple sequence alignment file %s contains '"}, {'id': '333', 'type': 'string', 'children': [], 'value': "'no sequences'"}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'UserWarning'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'}, {'id': '343', 'type': 'string', 'children': [], 'value': "'no sequences returned from deblur for file %s'"}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'output_msa_fp'}, {'id': '345', 'type': 'return_statement', 'children': ['346']}; {'id': '346', 'type': 'None', 'children': []}, {'id': '347', 'type': 'for_statement', 'children': ['348', '349', '350']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'seqs'}; {'id': '350', 'type': 'block', 'children': ['351', '365']}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'assignment', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '356', 'type': 'call', 'children': ['357', '362']}, {'id': '357', 'type': 'attribute', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'sequence'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '362', 'type': 'argument_list', 'children': ['363', '364']}, {'id': '363', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '364', 'type': 'string', 'children': [], 'value': "''"}, {'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': 'f'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'call', 'children': ['372', '375']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'to_fasta'}, {'id': '375', 'type': 'argument_list', 'children': []}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'output_no_chimeras_fp'}, {'id': '379', 'type': 'call', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'remove_chimeras_denovo_from_seqs'}, {'id': '381', 'type': 'argument_list', 'children': ['382', '383', '384']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'output_deblur_fp'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'working_dir'}; {'id': '384', 'type': 'keyword_argument', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'threads_per_sample'}, {'id': '387', 'type': 'expression_statement', 'children': ['388']}; {'id': '388', 'type': 'call', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '392', 'type': 'argument_list', 'children': ['393']}, {'id': '393', 'type': 'string', 'children': [], 'value': "'finished processing file'"}; {'id': '394', 'type': 'return_statement', 'children': ['395']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'output_no_chimeras_fp'}
def launch_workflow(seqs_fp, working_dir, mean_error, error_dist, indel_prob, indel_max, trim_length, left_trim_length, min_size, ref_fp, ref_db_fp, threads_per_sample=1, sim_thresh=None, coverage_thresh=None): logger = logging.getLogger(__name__) logger.info('--------------------------------------------------------') logger.info('launch_workflow for file %s' % seqs_fp) output_trim_fp = join(working_dir, "%s.trim" % basename(seqs_fp)) with open(output_trim_fp, 'w') as out_f: for label, seq in trim_seqs( input_seqs=sequence_generator(seqs_fp), trim_len=trim_length, left_trim_len=left_trim_length): out_f.write(">%s\n%s\n" % (label, seq)) output_derep_fp = join(working_dir, "%s.derep" % basename(output_trim_fp)) dereplicate_seqs(seqs_fp=output_trim_fp, output_fp=output_derep_fp, min_size=min_size, threads=threads_per_sample) output_artif_fp, num_seqs_left, _ = remove_artifacts_seqs(seqs_fp=output_derep_fp, ref_fp=ref_fp, working_dir=working_dir, ref_db_fp=ref_db_fp, negate=True, threads=threads_per_sample, sim_thresh=sim_thresh) if not output_artif_fp: warnings.warn('Problem removing artifacts from file %s' % seqs_fp, UserWarning) logger.warning('remove artifacts failed, aborting') return None if num_seqs_left > 1: output_msa_fp = join(working_dir, "%s.msa" % basename(output_artif_fp)) alignment = multiple_sequence_alignment(seqs_fp=output_artif_fp, threads=threads_per_sample) if not alignment: warnings.warn('Problem performing multiple sequence alignment ' 'on file %s' % seqs_fp, UserWarning) logger.warning('msa failed. aborting') return None elif num_seqs_left == 1: output_msa_fp = output_artif_fp else: err_msg = ('No sequences left after artifact removal in ' 'file %s' % seqs_fp) warnings.warn(err_msg, UserWarning) logger.warning(err_msg) return None output_deblur_fp = join(working_dir, "%s.deblur" % basename(output_msa_fp)) with open(output_deblur_fp, 'w') as f: seqs = deblur(sequence_generator(output_msa_fp), mean_error, error_dist, indel_prob, indel_max) if seqs is None: warnings.warn('multiple sequence alignment file %s contains ' 'no sequences' % output_msa_fp, UserWarning) logger.warn('no sequences returned from deblur for file %s' % output_msa_fp) return None for s in seqs: s.sequence = s.sequence.replace('-', '') f.write(s.to_fasta()) output_no_chimeras_fp = remove_chimeras_denovo_from_seqs( output_deblur_fp, working_dir, threads=threads_per_sample) logger.info('finished processing file') return output_no_chimeras_fp
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'logs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '22', '34', '48']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '13']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'loaded'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'load'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'logs'}, {'id': '25', 'type': 'attribute', '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': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'logs_dir'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'flat_directories'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logs'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '42', 'type': 'lambda', 'children': ['43', '45']}, {'id': '43', 'type': 'lambda_parameters', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'mod_time'}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'logs'}
def logs(self): if not self.parent.loaded: self.parent.load() logs = self.parent.p.logs_dir.flat_directories logs.sort(key=lambda x: x.mod_time) return logs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_string_by_pairs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'strings'}, {'id': '5', 'type': 'block', 'children': ['6', '15', '19', '26', '80']}; {'id': '6', 'type': 'assert_statement', 'children': ['7']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '14'], 'value': '=='}; {'id': '8', 'type': 'binary_operator', 'children': ['9', '13'], 'value': '%'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'strings'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'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': 'strings'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '26', 'type': 'while_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'strings'}; {'id': '28', 'type': 'block', 'children': ['29', '37']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'strings'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '41', '45']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'candidate'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'strings'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '54']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '53'], 'value': '=='}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'count_string_diff'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'candidate'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'block', 'children': ['55', '66', '72', '79']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '58', 'type': 'list', 'children': ['59', '60'], 'value': '[template, strings.pop(i)]'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'strings'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pair'}, {'id': '79', 'type': 'break_statement', 'children': []}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'pairs'}
def sort_string_by_pairs(strings): assert len(strings) % 2 == 0 pairs = [] strings = list(strings) while strings: template = strings.pop() for i, candidate in enumerate(strings): if count_string_diff(template, candidate) == 1: pair = [template, strings.pop(i)] pair.sort() pairs.append(pair) break return pairs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'}, {'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': 'dre'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "r'(\\d+)'"}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '32']}, {'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': 's'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dre'}
def natural_sort(item): dre = re.compile(r'(\d+)') return [int(s) if s.isdigit() else s.lower() for s in re.split(dre, item)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_elementary_intervals'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '61', '71', '77']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'try_statement', 'children': ['12', '48']}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '16', 'type': 'block', 'children': ['17', '35']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '24']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '23'], 'value': '!='}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '%'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Interval malformed %s. Allways specify start and end position for interval.'"}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'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': 'coords'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'list', 'children': ['42', '45'], 'value': '[interval[0],interval[1]]'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'except_clause', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '%'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'Interval malformed %s. Allways specify start and end position for interval.'"}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'return_statement', 'children': ['78']}
def get_elementary_intervals(self, features): coords = [] try: for interval in features: if len(interval) != 3: raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval)) coords.extend([interval[0],interval[1]]) except IndexError: raise SyntaxError('Interval malformed %s. Allways specify start and end position for interval.' % str(interval)) coords = list(set(coords)) coords.sort() return coords
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convtable2dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'convtable'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'locale'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '100']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rdict'}, {'id': '13', 'type': 'conditional_expression', 'children': ['14', '19', '20'], 'value': 'if'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'convtable'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '45', '76']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'}, {'id': '27', 'type': 'string', 'children': [], 'value': "':uni'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'locale'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '42']}, {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'rdict'}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '41', 'type': 'string', 'children': [], 'value': "':uni'"}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'locale'}, {'id': '45', 'type': 'elif_clause', 'children': ['46', '54']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '53'], 'value': '=='}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'locale'}, {'id': '49', 'type': 'slice', 'children': ['50', '51']}; {'id': '50', 'type': 'colon', 'children': []}, {'id': '51', 'type': 'unary_operator', 'children': ['52'], 'value': '-'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'zh-han'"}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'locale'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '67']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rdict'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'locale'}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'id': '77', 'type': 'block', 'children': ['78', '86']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'fallback'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'locale'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '93']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'rdict'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rdict'}
def convtable2dict(convtable, locale, update=None): rdict = update.copy() if update else {} for r in convtable: if ':uni' in r: if locale in r: rdict[r[':uni']] = r[locale] elif locale[:-1] == 'zh-han': if locale in r: for word in r.values(): rdict[word] = r[locale] else: v = fallback(locale, r) for word in r.values(): rdict[word] = v return rdict
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 're_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '21', '38']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'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': 'data'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'for_statement', 'children': ['22', '25', '29']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'number'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'new_data'}
def re_sort(data): keys = sorted(data.keys()) new_data = {} for number, key in enumerate(keys): new_data[number] = data[key] return new_data
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'natural_sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '5', 'type': 'block', 'children': ['6', '34', '43']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}, {'id': '7', 'type': 'function_name', 'children': [], 'value': 'sortkey'}; {'id': '8', 'type': 'parameters', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'list_comprehension', 'children': ['13', '25']}, {'id': '13', 'type': 'parenthesized_expression', 'children': ['14'], 'value': '()'}; {'id': '14', 'type': 'conditional_expression', 'children': ['15', '19', '24'], 'value': 'if'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'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': 'c'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isdigit'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'numbers'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "r'(\\d+)'"}, {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'}
def natural_sorted(iterable): def sortkey(x): return [(int(c) if c.isdigit() else c) for c in re.split(numbers, x)] numbers = re.compile(r'(\d+)') return sorted(iterable, key=sortkey)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'QuerySet'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}, {'id': '11', 'type': 'block', 'children': ['12', '30', '50', '81']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'missing_keys'}, {'id': '15', 'type': 'list_comprehension', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '20', 'type': 'if_clause', 'children': ['21']}, {'id': '21', 'type': 'not_operator', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_reverse_index'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys_and_values'}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '43', '46']}; {'id': '34', 'type': 'tuple', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'subscript', 'children': ['37', '42']}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_reverse_index'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'missing_keys'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}, {'id': '53', 'type': 'list_comprehension', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'kv'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kv'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '71']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'keys_and_values'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '65', 'type': 'lambda', 'children': ['66', '68']}; {'id': '66', 'type': 'lambda_parameters', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '73', 'type': 'conditional_expression', 'children': ['74', '75', '80'], 'value': 'if'}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': '=='}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'QuerySet'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}; {'id': '80', 'type': 'False', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '87', '92', '103']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '=='}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'QuerySet'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '+'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'missing_keys'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '98']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'QuerySet'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted_keys'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'missing_keys'}, {'id': '103', 'type': 'else_clause', 'children': ['104']}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'raise_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'Unexpected order value: {:d}'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}
def sort_keys(self, keys, order=QuerySet.ASCENDING): missing_keys = [ key for key in keys if not len(self._reverse_index[key]) ] keys_and_values = [ (key, self._reverse_index[key][0]) for key in keys if key not in missing_keys ] sorted_keys = [ kv[0] for kv in sorted( keys_and_values, key=lambda x: x[1], reverse=True if order == QuerySet.DESCENDING else False) ] if order == QuerySet.ASCENDING: return missing_keys + sorted_keys elif order == QuerySet.DESCENDING: return sorted_keys + missing_keys else: raise ValueError('Unexpected order value: {:d}'.format(order))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'options'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '18', '27', '38']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '9', 'type': 'call', 'children': ['10', '17']}; {'id': '10', 'type': 'attribute', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'opt'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '41', 'type': 'block', 'children': ['42', '51']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'opt'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'yield', 'children': ['58']}; {'id': '58', 'type': 'expression_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'opt'}
def options(self): keys = self.__class__.__dict__.copy() keys.update(self.__dict__) keys = sorted(keys.keys()) for opt in keys: val = self.get(opt) if val is not None: yield opt, val
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_tidy'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'block', 'children': ['8']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '12', '22']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'no_overlap'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'remove_overlap'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'no_contiguous'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_sort'}, {'id': '29', 'type': 'argument_list', 'children': []}
def _tidy(self) -> None: if self.no_overlap: self.remove_overlap(self.no_contiguous) else: self._sort()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29', '35']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'index_list_for_sort_order'}, {'id': '3', 'type': 'parameters', 'children': ['4', '12', '24']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '23']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'generic_type', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Callable'}, {'id': '17', 'type': 'type_parameter', 'children': ['18', '21']}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'list', 'children': ['20'], 'value': '[Any]'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'id': '21', 'type': 'type', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'typed_default_parameter', 'children': ['25', '26', '28']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '26', 'type': 'type', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'generic_type', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '32', 'type': 'type_parameter', 'children': ['33']}, {'id': '33', 'type': 'type', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '35', 'type': 'block', 'children': ['36', '57', '73', '89']}; {'id': '36', 'type': 'function_definition', 'children': ['37', '38', '49']}, {'id': '37', 'type': 'function_name', 'children': [], 'value': 'key_with_user_func'}; {'id': '38', 'type': 'parameters', 'children': ['39']}, {'id': '39', 'type': 'typed_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'idx_val'}, {'id': '41', 'type': 'type', 'children': ['42']}; {'id': '42', 'type': 'generic_type', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '44', 'type': 'type_parameter', 'children': ['45', '47']}, {'id': '45', 'type': 'type', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '47', 'type': 'type', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'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': 'key'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'idx_val'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '59', '64']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'key_with_user_func'}; {'id': '64', 'type': 'else_clause', 'children': ['65']}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'index_value_list'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '83', '86']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '96']}, {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_'}
def index_list_for_sort_order(x: List[Any], key: Callable[[Any], Any] = None, reverse: bool = False) -> List[int]: def key_with_user_func(idx_val: Tuple[int, Any]): return key(idx_val[1]) if key: sort_key = key_with_user_func else: sort_key = itemgetter(1) index_value_list = sorted(enumerate(x), key=sort_key, reverse=reverse) return [i for i, _ in index_value_list]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_list_by_index_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '12']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'indexes'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'generic_type', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '17', 'type': 'type_parameter', 'children': ['18']}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '29']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '27', 'type': 'slice', 'children': ['28']}; {'id': '28', 'type': 'colon', 'children': []}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'indexes'}
def sort_list_by_index_list(x: List[Any], indexes: List[int]) -> None: x[:] = [x[i] for i in indexes]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetch_all_first_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'select_statement'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Select'}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'generic_type', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '15', 'type': 'type_parameter', 'children': ['16']}; {'id': '16', 'type': 'type', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '18', 'type': 'block', 'children': ['19', '28']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'select_statement'}; {'id': '28', 'type': 'try_statement', 'children': ['29', '38']}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'list_comprehension', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '38', 'type': 'except_clause', 'children': ['39', '43']}, {'id': '39', 'type': 'as_pattern', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '41', 'type': 'as_pattern_target', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'e'}, {'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': 'MultipleResultsFound'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'e'}
def fetch_all_first_values(session: Session, select_statement: Select) -> List[Any]: rows = session.execute(select_statement) try: return [row[0] for row in rows] except ValueError as e: raise MultipleResultsFound(str(e))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'atoi'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'type', 'children': ['9']}, {'id': '9', 'type': 'generic_type', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Union'}, {'id': '11', 'type': 'type_parameter', 'children': ['12', '14']}; {'id': '12', 'type': 'type', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'conditional_expression', 'children': ['19', '23', '28'], 'value': 'if'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'isdigit'}, {'id': '27', 'type': 'argument_list', 'children': []}
def atoi(text: str) -> Union[int, str]: return int(text) if text.isdigit() else text
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reducer_metro'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'metro'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '7', 'type': 'block', 'children': ['8', '17']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'lookup'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'CachedLookup'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'POI_GEOHASH_PRECISION'}, {'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': 'value'}, {'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': 'values'}, {'id': '25', 'type': 'block', 'children': ['26', '33']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '32']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'type_tag'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lonlat'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '70']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'type_tag'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '62']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'geometry'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '56']}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'Point'"}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'coordinates'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'project'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'lonlat'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tags'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72', '79', '83', '95', '141']}; {'id': '72', 'type': 'if_statement', 'children': ['73', '77']}, {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'data_store'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': []}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'poi_names'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '92']}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'buffer_size'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'POI_DISTANCE'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'multiple'}; {'id': '94', 'type': 'True', 'children': []}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '105']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'poi'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'lonlat'}, {'id': '103', 'type': 'dictionary_splat', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '105', 'type': 'block', 'children': ['106', '118']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'has_tag'}, {'id': '109', 'type': 'list_comprehension', 'children': ['110', '115']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'poi'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'tags'"}, {'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'POI_TAGS'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '129']}, {'id': '119', 'type': 'boolean_operator', 'children': ['120', '124'], 'value': 'and'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'has_tag'}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'poi'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'tags'"}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'poi_names'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'subscript', 'children': ['137', '140']}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'poi'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'tags'"}; {'id': '140', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '141', 'type': 'for_statement', 'children': ['142', '143', '147']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'poi'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'poi_names'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'yield', 'children': ['150']}; {'id': '150', 'type': 'expression_list', 'children': ['151', '154']}, {'id': '151', 'type': 'tuple', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'metro'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'poi'}
def reducer_metro(self, metro, values): lookup = CachedLookup(precision=POI_GEOHASH_PRECISION) for i, value in enumerate(values): type_tag, lonlat, data = value if type_tag == 1: lookup.insert(i, dict( geometry=dict(type='Point', coordinates=project(lonlat)), properties=dict(tags=data) )) else: if not lookup.data_store: return poi_names = [] kwargs = dict(buffer_size=POI_DISTANCE, multiple=True) for poi in lookup.get(lonlat, **kwargs): has_tag = [ tag in poi['tags'] for tag in POI_TAGS ] if any(has_tag) and 'name' in poi['tags']: poi_names.append(poi['tags']['name']) for poi in set(poi_names): yield (metro, poi), 1
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_file_extensions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'reportevery'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'generic_type', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '16', 'type': 'type_parameter', 'children': ['17']}, {'id': '17', 'type': 'type', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '19', 'type': 'block', 'children': ['20', '26', '30', '86']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'extensions'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'for_statement', 'children': ['31', '35', '41']}, {'id': '31', 'type': 'pattern_list', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '41', 'type': 'block', 'children': ['42', '46', '62']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'augmented_assignment', 'children': ['44', '45'], 'value': '+='}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'reportevery'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Walking directory {}: {!r}"'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '65', 'type': 'block', 'children': ['66', '79']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'pattern_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '71', 'type': 'call', 'children': ['72', '77']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'splitext'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'file'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'extensions'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'extensions'}
def list_file_extensions(path: str, reportevery: int = 1) -> List[str]: extensions = set() count = 0 for root, dirs, files in os.walk(path): count += 1 if count % reportevery == 0: log.debug("Walking directory {}: {!r}", count, root) for file in files: filename, ext = os.path.splitext(file) extensions.add(ext) return sorted(list(extensions))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_dependencies'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'exts'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '43', '161']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted_ext'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'features_from_sorted'}; {'id': '14', 'type': 'expression_list', 'children': ['15', '16']}, {'id': '15', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pending'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '26']}, {'id': '23', 'type': 'tuple', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'exts'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'retry'}; {'id': '32', 'type': 'conditional_expression', 'children': ['33', '39', '42'], 'value': 'if'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '38'], 'value': '*'}; {'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': 'exts'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '43', 'type': 'while_statement', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pending'}, {'id': '45', 'type': 'block', 'children': ['46', '57', '89', '97']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pending'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '71']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '65'], 'value': 'and'}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'Extractor'}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'Extractor'}, {'id': '71', 'type': 'block', 'children': ['72', '76']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '75', 'type': 'string', 'children': [], 'value': '"Only Extractor instances are allowed. Found {}."'}; {'id': '76', 'type': 'raise_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'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': 'msg'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'deps'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_dependencies'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'if_statement', 'children': ['98', '104', '141']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'deps'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'features_from_sorted'}; {'id': '104', 'type': 'block', 'children': ['105', '130']}, {'id': '105', 'type': 'if_statement', 'children': ['106', '111']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '>'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '111', 'type': 'block', 'children': ['112', '116']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '115', 'type': 'string', 'children': [], 'value': '"Maximun retry ({}) to sort achieved from extractor {}."'}; {'id': '116', 'type': 'raise_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'retry'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'pending'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'tuple', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '141', 'type': 'else_clause', 'children': ['142']}; {'id': '142', 'type': 'block', 'children': ['143', '150']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'sorted_ext'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'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': 'features_from_sorted'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'get_features'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'return_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'sorted_ext'}
def sort_by_dependencies(exts, retry=None): sorted_ext, features_from_sorted = [], set() pending = [(e, 0) for e in exts] retry = len(exts) * 100 if retry is None else retry while pending: ext, cnt = pending.pop(0) if not isinstance(ext, Extractor) and not issubclass(ext, Extractor): msg = "Only Extractor instances are allowed. Found {}." raise TypeError(msg.format(type(ext))) deps = ext.get_dependencies() if deps.difference(features_from_sorted): if cnt + 1 > retry: msg = "Maximun retry ({}) to sort achieved from extractor {}." raise RuntimeError(msg.format(retry, type(ext))) pending.append((ext, cnt + 1)) else: sorted_ext.append(ext) features_from_sorted.update(ext.get_features()) return tuple(sorted_ext)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_layers'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_layers'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '24']}, {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_layers'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'lambda', 'children': ['27', '29']}, {'id': '27', 'type': 'lambda_parameters', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}
def _sort_layers(self): self._layers = OrderedDict(sorted(self._layers.items(), key=lambda t: t[0]))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_sections'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '41', '67', '79']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'order_lc'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '16']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '24', 'type': 'generator_expression', 'children': ['25', '32', '35']}, {'id': '25', 'type': 'tuple', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '27', 'type': 'subscript', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'order_lc'}, {'id': '35', 'type': 'if_clause', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'in'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'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': 'sections'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '46', 'type': 'generator_expression', 'children': ['47', '54', '63']}, {'id': '47', 'type': 'tuple', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '56', 'type': 'call', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'if_clause', 'children': ['64']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'not'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'order_lc'}, {'id': '67', 'type': 'assert_statement', 'children': ['68']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '75'], 'value': '=='}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sections'}
def sort_sections(self, order): order_lc = [e.lower() for e in order] sections = OrderedDict( (k,self.sections[k]) for k in order_lc if k in self.sections) sections.update( (k,self.sections[k]) for k in self.sections.keys() if k not in order_lc) assert len(self.sections) == len(sections) self.sections = sections
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_iterable_as_iterable'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '23', '64', '75']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'function_definition', 'children': ['24', '25', '27']}; {'id': '24', 'type': 'function_name', 'children': [], 'value': 'get_value'}, {'id': '25', 'type': 'parameters', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'ti'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'try_statement', 'children': ['29', '37']}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ti'}, {'id': '37', 'type': 'except_clause', 'children': ['38']}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'while_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'True', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42', '51', '58']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ti'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'return_statement', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cache'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sorter'}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '80']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'yield', 'children': ['83']}, {'id': '83', 'type': 'generator_expression', 'children': ['84', '88']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'islice'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'c'}
def split_iterable_as_iterable(self, values): values = iter(enumerate(values)) cache = dict() def get_value(ti): try: return cache.pop(ti) except: while True: i, v = next(values) if i==ti: return v cache[i] = v s = iter(self.index.sorter) for c in self.count: yield (get_value(i) for i in itertools.islice(s, int(c)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_index'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'semantics'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'axis_default'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '15', 'type': 'True', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'lex_as_struct'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '49', '75', '93', '106']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '26']}, {'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': 'keys'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Index'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '38', '45']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '35'], 'value': 'and'}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '34'], 'value': 'is'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'BaseIndex'}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '37', 'type': 'False', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '45', 'type': 'else_clause', 'children': ['46']}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '49', 'type': 'if_statement', 'children': ['50', '55']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '58', '67']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'lex_as_struct'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'as_struct_array'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'list_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '67', 'type': 'else_clause', 'children': ['68']}; {'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': 'LexIndex'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '75', 'type': 'try_statement', 'children': ['76', '86']}; {'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': 'keys'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '86', 'type': 'except_clause', 'children': ['87']}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'Given object does not form a valid set of keys'"}, {'id': '93', 'type': 'if_statement', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '96', 'type': 'None', 'children': []}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'flatten'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'if_statement', 'children': ['107', '112', '131']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ndim'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '115', '121']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'BaseIndex'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'Index'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'stable'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ObjectIndex'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stable'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'stable'}
def as_index(keys, axis=semantics.axis_default, base=False, stable=True, lex_as_struct=False): if isinstance(keys, Index): if type(keys) is BaseIndex and base==False: keys = keys.keys else: return keys if isinstance(keys, tuple): if lex_as_struct: keys = as_struct_array(*keys) else: return LexIndex(keys, stable) try: keys = np.asarray(keys) except: raise TypeError('Given object does not form a valid set of keys') if axis is None: keys = keys.flatten() if keys.ndim==1: if base: return BaseIndex(keys) else: return Index(keys, stable=stable) else: return ObjectIndex(keys, axis, stable=stable)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'axis_as_object'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '9', 'type': 'block', 'children': ['10', '16', '34', '46', '59']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ascontiguousarray'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'rollaxis'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'arr'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ndim'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'nbytes'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '43'], 'value': '*'}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'itemsize'}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'voidtype'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'tuple', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'void'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'nbytes'}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '69']}, {'id': '61', 'type': 'attribute', 'children': ['62', '68']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'arr'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'voidtype'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'reshape'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'shape'}
def axis_as_object(arr, axis=-1): shape = arr.shape arr = np.ascontiguousarray(np.rollaxis(arr, axis, arr.ndim)) nbytes = arr.dtype.itemsize * shape[axis] voidtype = np.dtype((np.void, nbytes)) return arr.view(voidtype).reshape(np.delete(shape, axis))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rank'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'semantics'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'axis_default'}; {'id': '10', 'type': 'block', 'children': ['11', '19']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'as_index'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'index'}
def rank(keys, axis=semantics.axis_default): index = as_index(keys, axis) return index.rank
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'function'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '28']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'partial'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '21', 'type': 'dictionary', 'children': ['22']}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'descending'"}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_descending_sort_by'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'f'}
def sort_by(function): f = partial(sorted, key=function) f.attrs = {'descending': _descending_sort_by(function)} return f
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'in_sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '27']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bisect'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'bisect_left'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '24']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '>='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'index'}; {'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': 'values'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'False', 'children': []}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'}
def in_sorted(values, value): index = bisect.bisect_left(values, value) if index >= len(values): return False return values[index] == value
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'handle_keypress'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11', '24', '37', '50']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': '=='}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '10', 'type': 'string', 'children': [], 'value': '"esc"'}, {'id': '11', 'type': 'block', 'children': ['12', '18']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'save_file'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'raise_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'urwid'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ExitMainLoop'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'elif_clause', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '27', 'type': 'string', 'children': [], 'value': '"delete"'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'combine_focus_with_next'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'elif_clause', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"backspace"'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'walker'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'combine_focus_with_prev'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'elif_clause', 'children': ['51', '54']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '53', 'type': 'string', 'children': [], 'value': '"enter"'}; {'id': '54', 'type': 'block', 'children': ['55', '63', '73']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '62']}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'split_focus'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'view'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'keypress'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"down"'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '80']}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'view'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'keypress'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'size'}
def handle_keypress(self, k): if k == "esc": self.save_file() raise urwid.ExitMainLoop() elif k == "delete": self.walker.combine_focus_with_next() elif k == "backspace": self.walker.combine_focus_with_prev() elif k == "enter": self.walker.split_focus() self.view.keypress(size, "down") self.view.keypress(size, "home")
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fsort'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '23', '31']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''\n Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score.\n '''"}, {'id': '9', 'type': 'if_statement', 'children': ['10', '14']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '30']}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fsort'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}
def sorted(self, fsort): ''' Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per field level, with special field name for _score to sort by score. ''' if not self.params: self.params = dict() self.params['sort'] = fsort return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter_sources'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '41']}, {'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': 'filtered'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '12', 'type': 'expression_list', 'children': ['13', '14']}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '18', 'type': 'block', 'children': ['19', '25', '32']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'continue_statement', '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': 'filtered'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'source'}; {'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': 'hosts'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'host_name'"}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'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': 's'}, {'id': '51', 'type': 'call', 'children': ['52', '60']}; {'id': '52', 'type': 'attribute', 'children': ['53', '59']}, {'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': '_hosts_by_success'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'host_name'"}
def _filter_sources(self, sources): filtered, hosts = [], [] for source in sources: if 'error' in source: continue filtered.append(source) hosts.append(source['host_name']) return sorted(filtered, key=lambda s: self._hosts_by_success(hosts).index(s['host_name']))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cantons'}, {'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', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'canton'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '22', 'type': 'call', 'children': ['23', '30']}, {'id': '23', 'type': 'attribute', 'children': ['24', '29']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_locations'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'}
def get_cantons(self): return sorted(list(set([ location.canton for location in self.get_locations().values() ])))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_municipalities'}, {'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', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '9', 'type': 'argument_list', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'municipality'}; {'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '22', 'type': 'call', 'children': ['23', '30']}, {'id': '23', 'type': 'attribute', 'children': ['24', '29']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_locations'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'}
def get_municipalities(self): return sorted(list(set([ location.municipality for location in self.get_locations().values() ])))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '48', '58', '65']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Run raw SQL on the database, and receive relaxing output.\n This is sort of the foundational method that most of the\n others build on.\n '''"}, {'id': '13', 'type': 'try_statement', 'children': ['14', '26']}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cursor'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sql'}; {'id': '24', 'type': 'list_splat', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '26', 'type': 'except_clause', 'children': ['27', '32', '33']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sqlite3'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'InterfaceError'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'raise_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sqlite3'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'InterfaceError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '47'], 'value': '+'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'unicode'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'\\nTry converting types or pickling.'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'fetchall'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '__commit_if_necessary'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '73', '76']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'else_clause', 'children': ['77']}, {'id': '77', 'type': 'block', 'children': ['78', '97', '112']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'colnames'}, {'id': '81', 'type': 'list_comprehension', 'children': ['82', '90']}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cursor'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'description'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'rawdata'}; {'id': '100', 'type': 'list_comprehension', 'children': ['101', '109']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'colnames'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'rawdata'}
def execute(self, sql, *args, **kwargs): ''' Run raw SQL on the database, and receive relaxing output. This is sort of the foundational method that most of the others build on. ''' try: self.cursor.execute(sql, *args) except self.sqlite3.InterfaceError, msg: raise self.sqlite3.InterfaceError(unicode(msg) + '\nTry converting types or pickling.') rows = self.cursor.fetchall() self.__commit_if_necessary(kwargs) if None == self.cursor.description: return None else: colnames = [d[0].decode('utf-8') for d in self.cursor.description] rawdata = [OrderedDict(zip(colnames,row)) for row in rows] return rawdata
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_message'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '7', 'type': 'block', 'children': ['8', '29', '39', '50', '61', '65', '74', '98']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '16']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': '"allow_empty"'}, {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '26']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '21'], 'value': 'or'}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'isspace'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': 'r"\\r\\n|\\r|\\n"'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_check_1st_line'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'dictionary_splat', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'signature_lines'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_check_bullets'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '59', 'type': 'dictionary_splat', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_check_signatures'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'signature_lines'}; {'id': '72', 'type': 'dictionary_splat', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '74', 'type': 'function_definition', 'children': ['75', '76', '80']}, {'id': '75', 'type': 'function_name', 'children': [], 'value': '_format'}; {'id': '76', 'type': 'parameters', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'lineno'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"{0}: {1} {2}"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_messages_codes'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'list_splat', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '122']}, {'id': '105', 'type': 'lambda', 'children': ['106', '108']}; {'id': '106', 'type': 'lambda_parameters', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_format'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '114', '117']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '119', 'type': 'slice', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '121', 'type': 'colon', 'children': []}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'lambda', 'children': ['129', '131']}, {'id': '129', 'type': 'lambda_parameters', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}
def check_message(message, **kwargs): if kwargs.pop("allow_empty", False): if not message or message.isspace(): return [] lines = re.split(r"\r\n|\r|\n", message) errors = _check_1st_line(lines[0], **kwargs) err, signature_lines = _check_bullets(lines, **kwargs) errors += err errors += _check_signatures(signature_lines, **kwargs) def _format(code, lineno, args): return "{0}: {1} {2}".format(lineno, code, _messages_codes[code].format(*args)) return list(map(lambda x: _format(x[0], x[1], x[2:]), sorted(errors, key=lambda x: x[0])))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_getArrays'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'defaultValue'}, {'id': '7', 'type': 'block', 'children': ['8', '21', '43', '67']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'list_comprehension', 'children': ['15', '18']}, {'id': '15', 'type': 'tuple', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '36']}, {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'arrays'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'defaultValue'}, {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '53']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'viewkeys'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'arrays'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'arrays'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'arrays'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '67', 'type': 'return_statement', 'children': ['68']}
def _getArrays(items, attr, defaultValue): arrays = dict([(key, []) for key in attr]) for item in items: for key in attr: arrays[key].append(getattr(item, key, defaultValue)) for key in [_ for _ in viewkeys(arrays)]: arrays[key] = numpy.array(arrays[key]) return arrays
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_log_board_ports'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '6', 'type': 'block', 'children': ['7', '26']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ports'}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'lambda', 'children': ['17', '19']}, {'id': '17', 'type': 'lambda_parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '19', 'type': 'tuple', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tile_id'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'port'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_logln'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'ports: {0}'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '41', 'type': 'generator_expression', 'children': ['42', '58']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'{}({} {})'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '52', '55']}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'tile_id'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'p'}
def _log_board_ports(self, ports): ports = sorted(ports, key=lambda port: (port.tile_id, port.direction)) self._logln('ports: {0}'.format(' '.join('{}({} {})'.format(p.type.value, p.tile_id, p.direction) for p in ports)))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'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': 'identifier', 'children': [], 'value': 'attr'}; {'id': '6', 'type': 'block', 'children': ['7', '26']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '12', 'type': 'call', 'children': ['13', '25']}, {'id': '13', 'type': 'attribute', 'children': ['14', '24']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'Sorter'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '20', '23']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'category'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_entries'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort(self, attr): self.entries = Sorter(self.entries, self.category, attr).sort_entries() return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_visit'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'marked'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'tempmarked'}; {'id': '8', 'type': 'block', 'children': ['9', '14', '24']}, {'id': '9', 'type': 'assert_statement', 'children': ['10']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_pseudo'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tempmarked'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'feature graph is cyclic'"}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'marked'}; {'id': '28', 'type': 'block', 'children': ['29', '35', '41', '64', '83', '104', '110', '114']}, {'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': 'tempmarked'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'True', 'children': []}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'if_statement', 'children': ['42', '51']}; {'id': '42', 'type': 'boolean_operator', 'children': ['43', '48'], 'value': 'and'}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': 'is'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'siblings'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'is_toplevel'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'siblings'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '70']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': 'is'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'features'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '90']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '89'], 'value': '>'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'features'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'features'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'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': 'feature'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': '_visit'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'marked'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tempmarked'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'marked'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'True', 'children': []}; {'id': '110', 'type': 'delete_statement', 'children': ['111']}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tempmarked'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'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': 'L'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}
def _visit(self, L, marked, tempmarked): assert not self.is_pseudo if self in tempmarked: raise Exception('feature graph is cyclic') if self not in marked: tempmarked[self] = True features = list() if self.siblings is not None and self.is_toplevel: features.extend(reversed(self.siblings)) if self.children is not None: features.extend(reversed(self.children)) if len(features) > 0: for feature in features: feature._visit(L, marked, tempmarked) marked[self] = True del tempmarked[self] L.insert(0, self)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pseudoify'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '25', '31', '49', '67', '74', '80', '88', '96', '104', '123', '134', '145']}; {'id': '6', 'type': 'assert_statement', 'children': ['7']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'is_toplevel'}; {'id': '10', 'type': 'assert_statement', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_multi'}; {'id': '14', 'type': 'assert_statement', 'children': ['15']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '24'], 'value': '>'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'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': 'multi_rep'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'siblings'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'multi_rep'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '47'], 'value': '+'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'siblings'}, {'id': '47', 'type': 'list', 'children': ['48'], 'value': '[rep]'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'rep'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'list_comprehension', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '+'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'siblings'}, {'id': '65', 'type': 'list', 'children': ['66'], 'value': '[rep]'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'rep'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'Feature'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '_pseudo'}, {'id': '79', 'type': 'True', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_seqid'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_seqid'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'set_coord'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_strand'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_strand'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '112']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sibling'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '110'], 'value': '+'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'rep'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'siblings'}; {'id': '110', 'type': 'list', 'children': ['111'], 'value': '[rep]'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'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': 'parent'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'add_child'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sibling'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'rangecheck'}; {'id': '122', 'type': 'True', 'children': []}, {'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': 'parent'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'siblings'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'rep'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'siblings'}, {'id': '145', 'type': 'return_statement', 'children': ['146']}
def pseudoify(self): assert self.is_toplevel assert self.is_multi assert len(self.multi_rep.siblings) > 0 rep = self.multi_rep start = min([s.start for s in rep.siblings + [rep]]) end = max([s.end for s in rep.siblings + [rep]]) parent = Feature(None) parent._pseudo = True parent._seqid = self._seqid parent.set_coord(start, end) parent._strand = self._strand for sibling in rep.siblings + [rep]: parent.add_child(sibling, rangecheck=True) parent.children = sorted(parent.children) rep.siblings = sorted(rep.siblings) return parent
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'attribute_crawl'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '44']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '12', 'type': 'argument_list', 'children': []}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'block', 'children': ['17', '29']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'feature'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_attribute'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'as_list'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'union'}
def attribute_crawl(self, key): union = set() for feature in self: values = feature.get_attribute(key, as_list=True) if values is not None: union.update(set(values)) return union
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_findSamesetProteins'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'protToPeps'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '21', '28', '53', '59', '87']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'proteins'}; {'id': '12', 'type': 'conditional_expression', 'children': ['13', '17', '20'], 'value': 'if'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'viewkeys'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'protToPeps'}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ddict'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '31', 'type': 'block', 'children': ['32', '38']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'peptides'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'protToPeps'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'protein'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '51']}; {'id': '40', 'type': 'attribute', 'children': ['41', '50']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'peptides'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'protein'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'equalProteins'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '65']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'viewvalues'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'equalEvidence'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '73']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], 'value': '>'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'proteins'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'equalProteins'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'proteins'}, {'id': '87', 'type': 'return_statement', 'children': ['88']}
def _findSamesetProteins(protToPeps, proteins=None): proteins = viewkeys(protToPeps) if proteins is None else proteins equalEvidence = ddict(set) for protein in proteins: peptides = protToPeps[protein] equalEvidence[tuple(sorted(peptides))].add(protein) equalProteins = list() for proteins in viewvalues(equalEvidence): if len(proteins) > 1: equalProteins.append(tuple(sorted(proteins))) return equalProteins