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': 'previous'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '28']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_order_by'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'oldest'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'older'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_order_by'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'newest'"}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'newer'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'None', 'children': []}
def previous(self): if self._order_by == 'oldest': return self.older if self._order_by == 'newest': return self.newer return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'next'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '28']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_order_by'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'oldest'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'newer'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_order_by'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'newest'"}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'older'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'None', 'children': []}
def next(self): if self._order_by == 'oldest': return self.newer if self._order_by == 'newest': return self.older return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'newest'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '28']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_order_by'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'newest'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'first'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_order_by'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'oldest'"}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'tuple', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'x'}
def newest(self): if self._order_by == 'newest': return self.first if self._order_by == 'oldest': return self.last return max(self.entries, key=lambda x: (x.date, x.id))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'oldest'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '28']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': '=='}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_order_by'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'newest'"}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '22'], 'value': '=='}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_order_by'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'oldest'"}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'entries'}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'tuple', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '-'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'id'}
def oldest(self): if self._order_by == 'newest': return self.last if self._order_by == 'oldest': return self.first return min(self.entries, key=lambda x: (x.date, -x.id))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dataframe_cols'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '38', '47', '51', '69', '79', '83', '97', '116', '123', '156', '166']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cols'}, {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '37']}, {'id': '23', 'type': 'lambda', 'children': ['24', '26']}; {'id': '24', 'type': 'lambda_parameters', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'data_model'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_group_for_col'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'groupby'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'groups'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}; {'id': '50', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '51', 'type': 'try_statement', 'children': ['52', '62']}; {'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': 'names'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'Names'"}; {'id': '62', 'type': 'except_clause', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '68', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'no_group'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'}, {'id': '85', 'type': 'string', 'children': [], 'value': "''"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'no_group'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "''"}, {'id': '97', 'type': 'for_statement', 'children': ['98', '99', '103']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sorted_cols'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'k'}; {'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': 'ordered_cols'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'no_group'}, {'id': '123', 'type': 'try_statement', 'children': ['124', '152']}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'if_statement', 'children': ['126', '131']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': 'in'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}, {'id': '131', 'type': 'block', 'children': ['132', '141']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '148']}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}, {'id': '145', 'type': 'slice', 'children': ['146', '147']}; {'id': '146', 'type': 'colon', 'children': []}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'list', 'children': ['149'], 'value': '[self.name]'}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '152', 'type': 'except_clause', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'pass_statement', 'children': []}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '161', 'type': 'subscript', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'df'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ordered_cols'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'df'}
def sort_dataframe_cols(self): cols = self.df.columns groups = list(map(lambda x: self.data_model.get_group_for_col(self.dtype, x), cols)) sorted_cols = cols.groupby(groups) ordered_cols = [] try: names = sorted_cols.pop('Names') except KeyError: names = [] ordered_cols.extend(list(names)) no_group = [] if '' in sorted_cols: no_group = sorted_cols.pop('') for k in sorted(sorted_cols): ordered_cols.extend(sorted(sorted_cols[k])) ordered_cols.extend(no_group) try: if self.name in ordered_cols: ordered_cols.remove(self.name) ordered_cols[:0] = [self.name] except AttributeError: pass self.df = self.df[ordered_cols] return self.df
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_diclist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'undecorated'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_on'}; {'id': '6', 'type': 'block', 'children': ['7', '38', '44']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'decorated'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '30']}, {'id': '11', 'type': 'tuple', 'children': ['12', '29']}; {'id': '12', 'type': 'conditional_expression', 'children': ['13', '19', '26'], 'value': 'if'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'subscript', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'__len__'"}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sort_on'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '34']}, {'id': '31', 'type': 'tuple_pattern', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict_'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'undecorated'}; {'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': 'decorated'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'undecorated'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '49', 'type': 'for_in_clause', 'children': ['50', '53']}; {'id': '50', 'type': 'tuple_pattern', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'decorated'}
def sort_diclist(undecorated, sort_on): decorated = [(len(dict_[sort_on]) if hasattr(dict_[sort_on], '__len__') else dict_[ sort_on], index) for (index, dict_) in enumerate(undecorated)] decorated.sort() return[undecorated[index] for (key, index) in decorated]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_data_for_mean'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'direction_type_key'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '38', '46', '54', '61', '358']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '13']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11', '12']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dec_key'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'inc_key'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'meth_key'}, {'id': '13', 'type': 'expression_list', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'dec'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'inc'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'magic_method_codes'"}, {'id': '17', 'type': 'if_statement', 'children': ['18', '27']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'dir_dec'"}; {'id': '20', 'type': 'call', 'children': ['21', '26']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '34']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dec_key'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'meth_key'}; {'id': '34', 'type': 'expression_list', 'children': ['35', '36', '37']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'dir_dec'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'dir_inc'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'method_codes'"}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'n_lines'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'n_planes'}, {'id': '43', 'type': 'expression_list', 'children': ['44', '45']}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'L'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'fdata'}, {'id': '51', 'type': 'expression_list', 'children': ['52', '53']}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '53', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'E'}, {'id': '57', 'type': 'list', 'children': ['58', '59', '60'], 'value': '[0, 0, 0]'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '64', 'type': 'block', 'children': ['65', '86']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cart'}; {'id': '68', 'type': 'subscript', 'children': ['69', '85']}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'dir2cart'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'list', 'children': ['73', '79'], 'value': '[float(rec[dec_key]), float(rec[inc_key])]'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'dec_key'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '97', '166', '240', '314']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'direction_type_key'}, {'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', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '104', '116']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '=='}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'direction_type_key'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'p'"}; {'id': '104', 'type': 'block', 'children': ['105', '109']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'augmented_assignment', 'children': ['107', '108'], 'value': '+='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'n_planes'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'cart'}; {'id': '116', 'type': 'else_clause', 'children': ['117']}, {'id': '117', 'type': 'block', 'children': ['118', '122', '142', '150', '158']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '+='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'n_lines'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'fdata'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'list', 'children': ['129', '135', '141'], 'value': '[float(rec[dec_key]), float(rec[inc_key]), 1.]'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dec_key'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '141', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'augmented_assignment', 'children': ['144', '147'], 'value': '+='}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'augmented_assignment', 'children': ['152', '155'], 'value': '+='}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'augmented_assignment', 'children': ['160', '163'], 'value': '+='}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '166', 'type': 'elif_clause', 'children': ['167', '177']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'in'}; {'id': '168', 'type': 'string', 'children': [], 'value': "'method_codes'"}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '176', 'type': 'argument_list', 'children': []}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'if_statement', 'children': ['179', '184', '196']}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"DE-BFP"'}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'meth_key'}; {'id': '184', 'type': 'block', 'children': ['185', '189']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'augmented_assignment', 'children': ['187', '188'], 'value': '+='}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'n_planes'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'cart'}; {'id': '196', 'type': 'else_clause', 'children': ['197']}, {'id': '197', 'type': 'block', 'children': ['198', '202', '216', '224', '232']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'augmented_assignment', 'children': ['200', '201'], 'value': '+='}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'n_lines'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'fdata'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'list', 'children': ['209', '212', '215'], 'value': '[rec[dec_key], rec[inc_key], 1.]'}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'dec_key'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '215', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'augmented_assignment', 'children': ['218', '221'], 'value': '+='}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'augmented_assignment', 'children': ['226', '229'], 'value': '+='}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'augmented_assignment', 'children': ['234', '237'], 'value': '+='}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '236', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '240', 'type': 'elif_clause', 'children': ['241', '251']}, {'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': 'in'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'meth_key'}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '250', 'type': 'argument_list', 'children': []}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'if_statement', 'children': ['253', '258', '270']}, {'id': '253', 'type': 'comparison_operator', 'children': ['254', '255'], 'value': 'in'}; {'id': '254', 'type': 'string', 'children': [], 'value': '"DE-BFP"'}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'meth_key'}; {'id': '258', 'type': 'block', 'children': ['259', '263']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'augmented_assignment', 'children': ['261', '262'], 'value': '+='}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'n_planes'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'L'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'cart'}; {'id': '270', 'type': 'else_clause', 'children': ['271']}, {'id': '271', 'type': 'block', 'children': ['272', '276', '290', '298', '306']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'augmented_assignment', 'children': ['274', '275'], 'value': '+='}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'n_lines'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'fdata'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'list', 'children': ['283', '286', '289'], 'value': '[rec[dec_key], rec[inc_key], 1.]'}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'dec_key'}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '289', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'augmented_assignment', 'children': ['292', '295'], 'value': '+='}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '294', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '297', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'augmented_assignment', 'children': ['300', '303'], 'value': '+='}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'augmented_assignment', 'children': ['308', '311'], 'value': '+='}; {'id': '308', 'type': 'subscript', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '310', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '313', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '314', 'type': 'else_clause', 'children': ['315']}, {'id': '315', 'type': 'block', 'children': ['316', '320', '334', '342', '350']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'augmented_assignment', 'children': ['318', '319'], 'value': '+='}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'n_lines'}, {'id': '319', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'fdata'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'list', 'children': ['327', '330', '333'], 'value': '[rec[dec_key], rec[inc_key], 1.]'}, {'id': '327', 'type': 'subscript', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'dec_key'}; {'id': '330', 'type': 'subscript', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'inc_key'}, {'id': '333', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'augmented_assignment', 'children': ['336', '339'], 'value': '+='}; {'id': '336', 'type': 'subscript', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '341', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'augmented_assignment', 'children': ['344', '347'], 'value': '+='}; {'id': '344', 'type': 'subscript', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '346', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '347', 'type': 'subscript', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '349', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'augmented_assignment', 'children': ['352', '355'], 'value': '+='}; {'id': '352', 'type': 'subscript', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'E'}; {'id': '354', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '355', 'type': 'subscript', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'cart'}, {'id': '357', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '358', 'type': 'return_statement', 'children': ['359']}, {'id': '359', 'type': 'expression_list', 'children': ['360', '361', '362', '363', '364']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'fdata'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'n_lines'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'L'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'n_planes'}
def process_data_for_mean(data, direction_type_key): dec_key, inc_key, meth_key = 'dec', 'inc', 'magic_method_codes' if 'dir_dec' in data[0].keys(): dec_key, inc_key, meth_key = 'dir_dec', 'dir_inc', 'method_codes' n_lines, n_planes = 0, 0 L, fdata = [], [] E = [0, 0, 0] for rec in data: cart = dir2cart([float(rec[dec_key]), float(rec[inc_key])])[0] if direction_type_key in list(rec.keys()): if rec[direction_type_key] == 'p': n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([float(rec[dec_key]), float(rec[inc_key]), 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] elif 'method_codes' in list(rec.keys()): if "DE-BFP" in rec[meth_key]: n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] elif meth_key in list(rec.keys()): if "DE-BFP" in rec[meth_key]: n_planes += 1 L.append(cart) else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] else: n_lines += 1 fdata.append([rec[dec_key], rec[inc_key], 1.]) E[0] += cart[0] E[1] += cart[1] E[2] += cart[2] return fdata, n_lines, L, n_planes, E
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '9', '13', '41', '61', '89', '103', '111', '121', '132', '149', '159', '247']}, {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dir_path'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'inspec'}; {'id': '12', 'type': 'string', 'children': [], 'value': '"pmag_specimens.txt"'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'in'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'-WD'"}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '19', 'type': 'block', 'children': ['20', '31']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'-WD'"}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dir_path'}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '+'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '47']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'-h'"}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '47', 'type': 'block', 'children': ['48', '55']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'main'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '__doc__'}, {'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': 'sys'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'if_statement', 'children': ['62', '67']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'-f'"}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'argv'}, {'id': '67', 'type': 'block', 'children': ['68', '79']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ind'}, {'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': 'sys'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'-f'"}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'inspec'}; {'id': '82', 'type': 'subscript', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '+'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '92', 'type': 'subscript', 'children': ['93', '99']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'inspec'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '99', 'type': 'slice', 'children': ['100', '101']}; {'id': '100', 'type': 'colon', 'children': []}, {'id': '101', 'type': 'unary_operator', 'children': ['102'], 'value': '-'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'inspec'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '110'], 'value': '+'}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'dir_path'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'inspec'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ofile_base'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '+'}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dir_path'}, {'id': '117', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'pattern_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'prior_spec_data'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'file_type'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pmag'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'magic_read'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'inspec'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '!='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'file_type'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'pmag_specimens'"}; {'id': '136', 'type': 'block', 'children': ['137', '143']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'file_type'}; {'id': '142', 'type': 'string', 'children': [], 'value': '" this is not a valid pmag_specimens file"'}, {'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': 'sys'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '155']}, {'id': '151', 'type': 'pattern_list', 'children': ['152', '153', '154']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'specs'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'comps'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '155', 'type': 'expression_list', 'children': ['156', '157', '158']}; {'id': '156', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '157', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '158', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '159', 'type': 'for_statement', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'prior_spec_data'}; {'id': '162', 'type': 'block', 'children': ['163', '179', '197', '215', '231']}, {'id': '163', 'type': 'if_statement', 'children': ['164', '169']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': 'not'}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'er_specimen_name'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'specs'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'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': 'specs'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'er_specimen_name'"}, {'id': '179', 'type': 'if_statement', 'children': ['180', '190']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'not'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'specimen_comp_name'"}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '189', 'type': 'argument_list', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '196']}, {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '195', 'type': 'string', 'children': [], 'value': "'specimen_comp_name'"}; {'id': '196', 'type': 'string', 'children': [], 'value': "'A'"}, {'id': '197', 'type': 'if_statement', 'children': ['198', '208']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'not'}, {'id': '199', 'type': 'string', 'children': [], 'value': "'specimen_tilt_correction'"}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '207', 'type': 'argument_list', 'children': []}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '214']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'tilt_correction'"}; {'id': '214', 'type': 'string', 'children': [], 'value': "'-1'"}, {'id': '215', 'type': 'if_statement', 'children': ['216', '221']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '220'], 'value': 'not'}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '219', 'type': 'string', 'children': [], 'value': "'specimen_comp_name'"}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'comps'}, {'id': '221', 'type': 'block', 'children': ['222']}; {'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': 'comps'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'specimen_comp_name'"}, {'id': '231', 'type': 'if_statement', 'children': ['232', '237']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': 'not'}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '235', 'type': 'string', 'children': [], 'value': "'specimen_tilt_correction'"}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'coords'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'specimen_tilt_correction'"}, {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'coord'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'coords'}; {'id': '250', 'type': 'block', 'children': ['251', '256']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '256', 'type': 'for_statement', 'children': ['257', '258', '259']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'comps'}, {'id': '259', 'type': 'block', 'children': ['260', '265', '269', '293', '307', '316']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'comp'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'speclist'}; {'id': '268', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '269', 'type': 'for_statement', 'children': ['270', '271', '272']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'prior_spec_data'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'if_statement', 'children': ['274', '285']}; {'id': '274', 'type': 'boolean_operator', 'children': ['275', '280'], 'value': 'and'}, {'id': '275', 'type': 'comparison_operator', 'children': ['276', '279'], 'value': '=='}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'spec'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'specimen_tilt_correction'"}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '284'], 'value': '=='}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'specimen_comp_name'"}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'comp'}, {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'call', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'speclist'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'spec'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'ofile'}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '306'], 'value': '+'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '305'], 'value': '+'}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '304'], 'value': '+'}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '303'], 'value': '+'}; {'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '+'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ofile_base'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '304', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'.txt'"}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'pmag'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'magic_write'}; {'id': '312', 'type': 'argument_list', 'children': ['313', '314', '315']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'ofile'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'speclist'}, {'id': '315', 'type': 'string', 'children': [], 'value': "'pmag_specimens'"}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '319', 'type': 'argument_list', 'children': ['320', '321', '322', '323', '324', '325']}; {'id': '320', 'type': 'string', 'children': [], 'value': "'coordinate system: '"}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'coord'}; {'id': '322', 'type': 'string', 'children': [], 'value': "' component name: '"}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '324', 'type': 'string', 'children': [], 'value': "' saved in '"}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'ofile'}
def main(): dir_path='.' inspec="pmag_specimens.txt" if '-WD' in sys.argv: ind=sys.argv.index('-WD') dir_path=sys.argv[ind+1] if '-h' in sys.argv: print(main.__doc__) sys.exit() if '-f' in sys.argv: ind=sys.argv.index('-f') inspec=sys.argv[ind+1] basename=inspec.split('.')[:-1] inspec=dir_path+"/"+inspec ofile_base=dir_path+"/"+basename[0] prior_spec_data,file_type=pmag.magic_read(inspec) if file_type != 'pmag_specimens': print(file_type, " this is not a valid pmag_specimens file") sys.exit() specs,comps,coords=[],[],[] for spec in prior_spec_data: if spec['er_specimen_name'] not in specs:specs.append(spec['er_specimen_name']) if 'specimen_comp_name' not in list(spec.keys()):spec['specimen_comp_name']='A' if 'specimen_tilt_correction' not in list(spec.keys()):spec['tilt_correction']='-1' if spec['specimen_comp_name'] not in comps:comps.append(spec['specimen_comp_name']) if spec['specimen_tilt_correction'] not in coords:coords.append(spec['specimen_tilt_correction']) for coord in coords: print(coord) for comp in comps: print(comp) speclist=[] for spec in prior_spec_data: if spec['specimen_tilt_correction']==coord and spec['specimen_comp_name']==comp:speclist.append(spec) ofile=ofile_base+'_'+coord+'_'+comp+'.txt' pmag.magic_write(ofile,speclist,'pmag_specimens') print('coordinate system: ',coord,' component name: ',comp,' saved in ',ofile)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_magic_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_by_this_name'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '46', '52', '66', '70', '166', '172']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'DATA'}, {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'try_statement', 'children': ['13', '41']}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'with_statement', 'children': ['15', '25']}, {'id': '15', 'type': 'with_clause', 'children': ['16']}; {'id': '16', 'type': 'with_item', 'children': ['17']}, {'id': '17', 'type': 'as_pattern', 'children': ['18', '23']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '23', 'type': 'as_pattern_target', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'finput'}, {'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': 'lines'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'subscript', 'children': ['33', '38']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'finput'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'readlines'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'slice', 'children': ['39', '40']}, {'id': '39', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '40', 'type': 'colon', 'children': []}, {'id': '41', 'type': 'except_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '51', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '55', 'type': 'call', 'children': ['56', '64']}; {'id': '56', 'type': 'attribute', 'children': ['57', '63']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'error_strings'}, {'id': '69', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '70', 'type': 'for_statement', 'children': ['71', '72', '77']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '74', 'type': 'slice', 'children': ['75', '76']}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'colon', 'children': []}, {'id': '77', 'type': 'block', 'children': ['78', '82', '96', '116', '158']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}, {'id': '81', 'type': 'dictionary', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tmp_line'}, {'id': '85', 'type': 'call', 'children': ['86', '94']}; {'id': '86', 'type': 'attribute', 'children': ['87', '93']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '105']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'tmp_line'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '113']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'tmp_line'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '129']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': 'in'}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sort_by_this_name'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'DATA'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '128', 'type': 'argument_list', 'children': []}, {'id': '129', 'type': 'block', 'children': ['130', '141']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'error_string'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"-E- ERROR: magic file %s has more than one line for %s %s"'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137', '138']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'sort_by_this_name'}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sort_by_this_name'}, {'id': '141', 'type': 'if_statement', 'children': ['142', '145']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'not'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'error_string'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'error_strings'}, {'id': '145', 'type': 'block', 'children': ['146', '151']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'error_string'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'error_strings'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'error_string'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '165']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'DATA'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sort_by_this_name'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'tmp_data'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'finput'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'close'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'return_statement', 'children': ['173']}, {'id': '173', 'type': 'parenthesized_expression', 'children': ['174']}
def read_magic_file(self, path, sort_by_this_name): DATA = {} try: with open(path, 'r') as finput: lines = list(finput.readlines()[1:]) except FileNotFoundError: return [] line = lines[0] header = line.strip('\n').split('\t') error_strings = [] for line in lines[1:]: tmp_data = {} tmp_line = line.strip('\n').split('\t') for i in range(len(tmp_line)): tmp_data[header[i]] = tmp_line[i] if tmp_data[sort_by_this_name] in list(DATA.keys()): error_string = "-E- ERROR: magic file %s has more than one line for %s %s" % ( path, sort_by_this_name, tmp_data[sort_by_this_name]) if error_string not in error_strings: print(error_string) error_strings.append(error_string) DATA[tmp_data[sort_by_this_name]] = tmp_data finput.close() return(DATA)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'plot_teq'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fignum'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'araiblock'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'pars'}; {'id': '8', 'type': 'block', 'children': ['9', '21', '30', '36', '46', '85', '90', '132', '174', '197', '210', '224', '239', '253', '268', '282', '297', '304']}, {'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': 'first_Z'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'first_I'}; {'id': '14', 'type': 'expression_list', 'children': ['15', '18']}, {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'araiblock'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'araiblock'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'plt'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'figure'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'num'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fignum'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'clf'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '42']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ZIblock'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'IZblock'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pTblock'}; {'id': '42', 'type': 'expression_list', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'zrec'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'first_Z'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '56', '70']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '55'], 'value': '=='}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'zrec'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ZIblock'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'list', 'children': ['64', '67'], 'value': '[zrec[1], zrec[2]]'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'zrec'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'zrec'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'IZblock'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'list', 'children': ['79', '82'], 'value': '[zrec[1], zrec[2]]'}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'zrec'}, {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'zrec'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'plot_net'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'fignum'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94', '113']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '!='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pars'}, {'id': '93', 'type': 'string', 'children': [], 'value': '""'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'pattern_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '100', 'type': 'expression_list', 'children': ['101', '107']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pars'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"measurement_step_min"'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'pars'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"measurement_step_max"'}, {'id': '113', 'type': 'else_clause', 'children': ['114']}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '120']}, {'id': '117', 'type': 'pattern_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '120', 'type': 'expression_list', 'children': ['121', '126']}, {'id': '121', 'type': 'subscript', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'first_I'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'subscript', 'children': ['127', '131']}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'first_I'}, {'id': '129', 'type': 'unary_operator', 'children': ['130'], 'value': '-'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'irec'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'first_I'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '160']}, {'id': '137', 'type': 'boolean_operator', 'children': ['138', '155'], 'value': 'and'}; {'id': '138', 'type': 'boolean_operator', 'children': ['139', '150'], 'value': 'and'}, {'id': '139', 'type': 'boolean_operator', 'children': ['140', '145'], 'value': 'and'}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '!='}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'irec'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '!='}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'irec'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': '>='}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'irec'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '155', 'type': 'comparison_operator', 'children': ['156', '159'], 'value': '<='}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'irec'}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pTblock'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'list', 'children': ['168', '171'], 'value': '[irec[1], irec[2]]'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'irec'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'irec'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '195']}, {'id': '175', 'type': 'boolean_operator', 'children': ['176', '189'], 'value': 'and'}; {'id': '176', 'type': 'boolean_operator', 'children': ['177', '183'], 'value': 'and'}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '182'], 'value': '<'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ZIblock'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '188'], 'value': '<'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'IZblock'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '194'], 'value': '<'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'pTblock'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'return_statement', 'children': []}, {'id': '197', 'type': 'if_statement', 'children': ['198', '200']}; {'id': '198', 'type': 'not_operator', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'isServer'}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'figtext'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '208', '209']}, {'id': '207', 'type': 'float', 'children': [], 'value': '.02'}; {'id': '208', 'type': 'float', 'children': [], 'value': '.01'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'version_num'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '213', 'type': 'dictionary', 'children': ['214', '219']}; {'id': '214', 'type': 'pair', 'children': ['215', '216']}, {'id': '215', 'type': 'string', 'children': [], 'value': "'lower'"}; {'id': '216', 'type': 'list', 'children': ['217', '218'], 'value': "['o', 'r']"}, {'id': '217', 'type': 'string', 'children': [], 'value': "'o'"}; {'id': '218', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '219', 'type': 'pair', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'upper'"}, {'id': '221', 'type': 'list', 'children': ['222', '223'], 'value': "['o', 'm']"}; {'id': '222', 'type': 'string', 'children': [], 'value': "'o'"}, {'id': '223', 'type': 'string', 'children': [], 'value': "'m'"}; {'id': '224', 'type': 'if_statement', 'children': ['225', '231']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '230'], 'value': '>'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'ZIblock'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'plot_di_sym'}, {'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'fignum'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ZIblock'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '242', 'type': 'dictionary', 'children': ['243', '248']}, {'id': '243', 'type': 'pair', 'children': ['244', '245']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'lower'"}, {'id': '245', 'type': 'list', 'children': ['246', '247'], 'value': "['s', 'b']"}; {'id': '246', 'type': 'string', 'children': [], 'value': "'s'"}, {'id': '247', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '248', 'type': 'pair', 'children': ['249', '250']}, {'id': '249', 'type': 'string', 'children': [], 'value': "'upper'"}; {'id': '250', 'type': 'list', 'children': ['251', '252'], 'value': "['s', 'c']"}, {'id': '251', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '252', 'type': 'string', 'children': [], 'value': "'c'"}, {'id': '253', 'type': 'if_statement', 'children': ['254', '260']}; {'id': '254', 'type': 'comparison_operator', 'children': ['255', '259'], 'value': '>'}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'IZblock'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '260', 'type': 'block', 'children': ['261']}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'plot_di_sym'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '266', '267']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'fignum'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'IZblock'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'sym'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '271', 'type': 'dictionary', 'children': ['272', '277']}; {'id': '272', 'type': 'pair', 'children': ['273', '274']}, {'id': '273', 'type': 'string', 'children': [], 'value': "'lower'"}; {'id': '274', 'type': 'list', 'children': ['275', '276'], 'value': "['^', 'g']"}, {'id': '275', 'type': 'string', 'children': [], 'value': "'^'"}; {'id': '276', 'type': 'string', 'children': [], 'value': "'g'"}, {'id': '277', 'type': 'pair', 'children': ['278', '279']}; {'id': '278', 'type': 'string', 'children': [], 'value': "'upper'"}, {'id': '279', 'type': 'list', 'children': ['280', '281'], 'value': "['^', 'y']"}; {'id': '280', 'type': 'string', 'children': [], 'value': "'^'"}, {'id': '281', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '282', 'type': 'if_statement', 'children': ['283', '289']}, {'id': '283', 'type': 'comparison_operator', 'children': ['284', '288'], 'value': '>'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'pTblock'}; {'id': '288', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'plot_di_sym'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295', '296']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'fignum'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'pTblock'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'sym'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'plt'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}, {'id': '303', 'type': 'string', 'children': [], 'value': '"equal"'}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '309', 'type': 'argument_list', 'children': ['310', '312', '313']}; {'id': '310', 'type': 'unary_operator', 'children': ['311'], 'value': '-'}, {'id': '311', 'type': 'float', 'children': [], 'value': '1.1'}; {'id': '312', 'type': 'float', 'children': [], 'value': '1.15'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 's'}
def plot_teq(fignum, araiblock, s, pars): first_Z, first_I = araiblock[0], araiblock[1] plt.figure(num=fignum) plt.clf() ZIblock, IZblock, pTblock = [], [], [] for zrec in first_Z: if zrec[4] == 1: ZIblock.append([zrec[1], zrec[2]]) else: IZblock.append([zrec[1], zrec[2]]) plot_net(fignum) if pars != "": min, max = float(pars["measurement_step_min"]), float( pars["measurement_step_max"]) else: min, max = first_I[0][0], first_I[-1][0] for irec in first_I: if irec[1] != 0 and irec[1] != 0 and irec[0] >= min and irec[0] <= max: pTblock.append([irec[1], irec[2]]) if len(ZIblock) < 1 and len(IZblock) < 1 and len(pTblock) < 1: return if not isServer: plt.figtext(.02, .01, version_num) sym = {'lower': ['o', 'r'], 'upper': ['o', 'm']} if len(ZIblock) > 0: plot_di_sym(fignum, ZIblock, sym) sym = {'lower': ['s', 'b'], 'upper': ['s', 'c']} if len(IZblock) > 0: plot_di_sym(fignum, IZblock, sym) sym = {'lower': ['^', 'g'], 'upper': ['^', 'y']} if len(pTblock) > 0: plot_di_sym(fignum, pTblock, sym) plt.axis("equal") plt.text(-1.1, 1.15, s)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_records_map'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'records'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '21', '28', '35', '73', '80', '89', '96', '104', '113', '122', '157', '165', '177', '206', '213', '219', '238']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'l'}, {'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': 'records'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'key_records'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '27'], 'value': '*'}, {'id': '25', 'type': 'list', 'children': ['26'], 'value': '[None]'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': '"Parsing"'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '41', 'type': 'block', 'children': ['42', '50', '59']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'proto'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kv_pb'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'KeyValue'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ParseFromString'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'key_records'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '64', 'type': 'tuple', 'children': ['65', '70']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'proto'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'records'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'string', 'children': [], 'value': '"Sorting"'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'key_records'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cmp'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_compare_keys'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Writing"'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'mapper_spec'}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'mapreduce_spec'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'input_readers'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_get_params'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'mapper_spec'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'bucket_name'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'string', 'children': [], 'value': '"bucket_name"'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '125', 'type': 'parenthesized_expression', 'children': ['126']}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '146'], 'value': '+'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '145'], 'value': '+'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '142'], 'value': '+'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '141'], 'value': '+'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '138'], 'value': '+'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '137'], 'value': '+'}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'mapreduce_spec'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'mapreduce_id'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"/output-"'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'shard_id'}, {'id': '145', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'full_filename'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '%'}, {'id': '161', 'type': 'string', 'children': [], 'value': '"/%s/%s"'}; {'id': '162', 'type': 'tuple', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'bucket_name'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'filehandle'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cloudstorage'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'full_filename'}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"w"'}, {'id': '177', 'type': 'with_statement', 'children': ['178', '192']}; {'id': '178', 'type': 'with_clause', 'children': ['179']}, {'id': '179', 'type': 'with_item', 'children': ['180']}; {'id': '180', 'type': 'as_pattern', 'children': ['181', '190']}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'output_writers'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'GCSRecordsPool'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'filehandle'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '190', 'type': 'as_pattern_target', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'for_statement', 'children': ['194', '195', '196']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'key_record'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'key_records'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'key_record'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'string', 'children': [], 'value': '"Finalizing"'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'filehandle'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '218', 'type': 'argument_list', 'children': []}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': '_OutputFile'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '228']}, {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'key_name'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'full_filename'}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': '_OutputFile'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'get_root_key'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'ctx'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'mapreduce_id'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'put'}, {'id': '243', 'type': 'argument_list', 'children': []}
def _sort_records_map(records): ctx = context.get() l = len(records) key_records = [None] * l logging.debug("Parsing") for i in range(l): proto = kv_pb.KeyValue() proto.ParseFromString(records[i]) key_records[i] = (proto.key(), records[i]) logging.debug("Sorting") key_records.sort(cmp=_compare_keys) logging.debug("Writing") mapper_spec = ctx.mapreduce_spec.mapper params = input_readers._get_params(mapper_spec) bucket_name = params.get("bucket_name") filename = (ctx.mapreduce_spec.name + "/" + ctx.mapreduce_id + "/output-" + ctx.shard_id + "-" + str(int(time.time()))) full_filename = "/%s/%s" % (bucket_name, filename) filehandle = cloudstorage.open(full_filename, mode="w") with output_writers.GCSRecordsPool(filehandle, ctx=ctx) as pool: for key_record in key_records: pool.append(key_record[1]) logging.debug("Finalizing") filehandle.close() entity = _OutputFile(key_name=full_filename, parent=_OutputFile.get_root_key(ctx.mapreduce_id)) entity.put()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_all_by_mapreduce_state'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'calculate_keys_by_mapreduce_state'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'while_statement', 'children': ['21', '27']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': '<'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '27', 'type': 'block', 'children': ['28', '54', '61']}; {'id': '28', 'type': 'decorated_definition', 'children': ['29', '33']}, {'id': '29', 'type': 'decorator', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'non_transactional'}, {'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']}; {'id': '34', 'type': 'function_name', 'children': [], 'value': 'no_tx_get'}, {'id': '35', 'type': 'parameters', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '46', 'type': 'slice', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'colon', 'children': []}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_MAX_STATES_IN_MEMORY'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'no_tx_get'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '64', 'type': 'block', 'children': ['65', '69']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'augmented_assignment', 'children': ['67', '68'], 'value': '+='}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'yield', 'children': ['76']}
def find_all_by_mapreduce_state(cls, mapreduce_state): keys = cls.calculate_keys_by_mapreduce_state(mapreduce_state) i = 0 while i < len(keys): @db.non_transactional def no_tx_get(i): return db.get(keys[i:i+cls._MAX_STATES_IN_MEMORY]) states = no_tx_get(i) for s in states: i += 1 if s is not None: yield s
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_keys_by_mapreduce_state'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '18', '61']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '30']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'attribute', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'mapreduce_spec'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'mapper'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'shard_count'}; {'id': '30', 'type': 'block', 'children': ['31', '49']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shard_id'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'shard_id_from_number'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '48']}, {'id': '39', 'type': 'call', 'children': ['40', '47']}; {'id': '40', 'type': 'attribute', 'children': ['41', '46']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mapreduce_state'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get_key_by_shard_id'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'shard_id'}, {'id': '61', 'type': 'return_statement', 'children': ['62']}
def calculate_keys_by_mapreduce_state(cls, mapreduce_state): if mapreduce_state is None: return [] keys = [] for i in range(mapreduce_state.mapreduce_spec.mapper.shard_count): shard_id = cls.shard_id_from_number(mapreduce_state.key().name(), i) keys.append(cls.get_key_by_shard_id(shard_id)) return keys
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '29']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'contiguous'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'can_query'}, {'id': '9', 'type': 'attribute', 'children': ['10', '28']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '22']}, {'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': 'repeat'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'False', 'children': []}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33', '43', '47', '193', '197', '278', '295']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'n must be >= 1'"}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51', '181']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'can_query'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'if_statement', 'children': ['53', '55', '148']}, {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'contiguous'}, {'id': '55', 'type': 'block', 'children': ['56', '66']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ns_keys'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_namespace_keys'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '69', '72']}, {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'ns_keys'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74', '129']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '81']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '<='}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ns_keys'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '81', 'type': 'block', 'children': ['82', '86', '116']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ns_range'}, {'id': '85', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ns_key'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ns_keys'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '106', '113']}, {'id': '99', 'type': 'boolean_operator', 'children': ['100', '105'], 'value': 'or'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'ns_key'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'string', 'children': [], 'value': "''"}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '112'], 'value': 'or'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ns_key'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'string', 'children': [], 'value': "''"}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ns_range'}, {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '123', 'type': 'lambda', 'children': ['124', '126']}; {'id': '124', 'type': 'lambda_parameters', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '132', 'type': 'list', 'children': ['133'], 'value': "[NamespaceRange(ns_keys[0].name() or '', _app=_app)]"}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '145']}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '144'], 'value': 'or'}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ns_keys'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '143', 'type': 'argument_list', 'children': []}; {'id': '144', 'type': 'string', 'children': [], 'value': "''"}, {'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '148', 'type': 'else_clause', 'children': ['149']}, {'id': '149', 'type': 'block', 'children': ['150', '163', '176']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ns_range'}, {'id': '153', 'type': 'call', 'children': ['154', '162']}; {'id': '154', 'type': 'attribute', 'children': ['155', '161']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'normalized_start'}; {'id': '162', 'type': 'argument_list', 'children': []}, {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'return_statement', 'children': ['169']}, {'id': '169', 'type': 'list', 'children': ['170'], 'value': '[NamespaceRange(_app=_app)]'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': '[ns_range]'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ns_range'}, {'id': '181', 'type': 'else_clause', 'children': ['182']}; {'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': 'ranges'}; {'id': '186', 'type': 'list', 'children': ['187'], 'value': '[NamespaceRange(_app=_app)]'}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '196', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '197', 'type': 'while_statement', 'children': ['198', '212']}; {'id': '198', 'type': 'boolean_operator', 'children': ['199', '200'], 'value': 'and'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '211'], 'value': '<'}, {'id': '201', 'type': 'parenthesized_expression', 'children': ['202']}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '207'], 'value': '+'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'singles'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '212', 'type': 'block', 'children': ['213', '222']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'namespace_range'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '226', '234']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'namespace_range'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'is_single_namespace'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'singles'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'namespace_range'}; {'id': '234', 'type': 'else_clause', 'children': ['235']}, {'id': '235', 'type': 'block', 'children': ['236', '246', '259', '271']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'pattern_list', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'right'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'namespace_range'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'split_range'}, {'id': '245', 'type': 'argument_list', 'children': []}; {'id': '246', 'type': 'if_statement', 'children': ['247', '250']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'can_query'}, {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'block', 'children': ['251']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'right'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'normalized_start'}; {'id': '258', 'type': 'argument_list', 'children': []}, {'id': '259', 'type': 'if_statement', 'children': ['260', '263']}; {'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': 'is'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '262', 'type': 'None', 'children': []}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'ranges'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'right'}, {'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': 'ranges'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}, {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '283', 'type': 'argument_list', 'children': ['284', '287']}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '+'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'ranges'}, {'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '289', 'type': 'lambda', 'children': ['290', '292']}; {'id': '290', 'type': 'lambda_parameters', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'ns_range'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}, {'id': '295', 'type': 'if_statement', 'children': ['296', '297', '393']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'contiguous'}, {'id': '297', 'type': 'block', 'children': ['298', '310', '314', '391']}; {'id': '298', 'type': 'if_statement', 'children': ['299', '301']}, {'id': '299', 'type': 'not_operator', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'return_statement', 'children': ['303']}, {'id': '303', 'type': 'list', 'children': ['304'], 'value': '[NamespaceRange(_app=_app)]'}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'keyword_argument', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}, {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'continuous_ns_ranges'}, {'id': '313', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '314', 'type': 'for_statement', 'children': ['315', '316', '323']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '316', 'type': 'call', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}, {'id': '323', 'type': 'block', 'children': ['324', '343', '377']}; {'id': '324', 'type': 'if_statement', 'children': ['325', '328', '333']}, {'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': '=='}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '327', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'MIN_NAMESPACE'}, {'id': '333', 'type': 'else_clause', 'children': ['334']}; {'id': '334', 'type': 'block', 'children': ['335']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}; {'id': '338', 'type': 'attribute', 'children': ['339', '342']}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}, {'id': '343', 'type': 'if_statement', 'children': ['344', '352', '357']}; {'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': '=='}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '346', 'type': 'binary_operator', 'children': ['347', '351'], 'value': '-'}, {'id': '347', 'type': 'call', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}, {'id': '351', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '352', 'type': 'block', 'children': ['353']}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'namespace_end'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'MAX_NAMESPACE'}, {'id': '357', 'type': 'else_clause', 'children': ['358']}; {'id': '358', 'type': 'block', 'children': ['359']}, {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'assignment', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'namespace_end'}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': '_ord_to_namespace'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'binary_operator', 'children': ['366', '376'], 'value': '-'}; {'id': '366', 'type': 'call', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': '_namespace_to_ord'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'attribute', 'children': ['370', '375']}; {'id': '370', 'type': 'subscript', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'ns_ranges'}; {'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '+'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '374', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}; {'id': '376', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '377', 'type': 'expression_statement', 'children': ['378']}; {'id': '378', 'type': 'call', 'children': ['379', '382']}, {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'continuous_ns_ranges'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'NamespaceRange'}, {'id': '385', 'type': 'argument_list', 'children': ['386', '387', '388']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'namespace_start'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'namespace_end'}; {'id': '388', 'type': 'keyword_argument', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': '_app'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': '_app'}, {'id': '391', 'type': 'return_statement', 'children': ['392']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'continuous_ns_ranges'}, {'id': '393', 'type': 'else_clause', 'children': ['394']}; {'id': '394', 'type': 'block', 'children': ['395']}, {'id': '395', 'type': 'return_statement', 'children': ['396']}
def split(cls, n, contiguous, can_query=itertools.chain(itertools.repeat(True, 50), itertools.repeat(False)).next, _app=None): if n < 1: raise ValueError('n must be >= 1') ranges = None if can_query(): if not contiguous: ns_keys = get_namespace_keys(_app, n + 1) if not ns_keys: return [] else: if len(ns_keys) <= n: ns_range = [] for ns_key in ns_keys: ns_range.append(NamespaceRange(ns_key.name() or '', ns_key.name() or '', _app=_app)) return sorted(ns_range, key=lambda ns_range: ns_range.namespace_start) ranges = [NamespaceRange(ns_keys[0].name() or '', _app=_app)] else: ns_range = NamespaceRange(_app=_app).normalized_start() if ns_range is None: return [NamespaceRange(_app=_app)] ranges = [ns_range] else: ranges = [NamespaceRange(_app=_app)] singles = [] while ranges and (len(ranges) + len(singles)) < n: namespace_range = ranges.pop(0) if namespace_range.is_single_namespace: singles.append(namespace_range) else: left, right = namespace_range.split_range() if can_query(): right = right.normalized_start() if right is not None: ranges.append(right) ranges.append(left) ns_ranges = sorted(singles + ranges, key=lambda ns_range: ns_range.namespace_start) if contiguous: if not ns_ranges: return [NamespaceRange(_app=_app)] continuous_ns_ranges = [] for i in range(len(ns_ranges)): if i == 0: namespace_start = MIN_NAMESPACE else: namespace_start = ns_ranges[i].namespace_start if i == len(ns_ranges) - 1: namespace_end = MAX_NAMESPACE else: namespace_end = _ord_to_namespace( _namespace_to_ord(ns_ranges[i+1].namespace_start) - 1) continuous_ns_ranges.append(NamespaceRange(namespace_start, namespace_end, _app=_app)) return continuous_ns_ranges else: return ns_ranges
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_raw_members'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'leaderboard_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'members_only'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '12', 'type': 'block', 'children': ['13', '15', '29']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'''\n Parse the raw leaders data as returned from a given leader board query. Do associative\n lookups with the member to rank, score and potentially sort the results.\n @param leaderboard_name [String] Name of the leaderboard.\n @param members [List] A list of members as returned from a sorted set range query\n @param members_only [bool] Set True to return the members as is, Default is False.\n @param options [Hash] Options to be used when retrieving the page from the named leaderboard.\n @return a list of members.\n '''"}, {'id': '15', 'type': 'if_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'members_only'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'list_comprehension', 'children': ['20', '26']}; {'id': '20', 'type': 'dictionary', 'children': ['21']}, {'id': '21', 'type': 'pair', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'MEMBER_KEY'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '31', '42']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ranked_in_list_in'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'leaderboard_name'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'members'}; {'id': '40', 'type': 'dictionary_splat', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '42', 'type': 'else_clause', 'children': ['43']}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}
def _parse_raw_members( self, leaderboard_name, members, members_only=False, **options): ''' Parse the raw leaders data as returned from a given leader board query. Do associative lookups with the member to rank, score and potentially sort the results. @param leaderboard_name [String] Name of the leaderboard. @param members [List] A list of members as returned from a sorted set range query @param members_only [bool] Set True to return the members as is, Default is False. @param options [Hash] Options to be used when retrieving the page from the named leaderboard. @return a list of members. ''' if members_only: return [{self.MEMBER_KEY: m} for m in members] if members: return self.ranked_in_list_in(leaderboard_name, members, **options) else: return []
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '163']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37', '40', '43', '46', '49', '52', '55', '58', '61', '64', '67', '70', '73', '76', '79', '82', '85', '88', '91', '94', '97', '100', '103', '106', '109', '112', '115', '118', '121', '124', '127', '130', '133', '136', '139', '142', '145', '148', '151', '154', '157', '160']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'artist'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'artist_id'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'combined'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'style'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'mood'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'results'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'max_tempo'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'min_tempo'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_duration'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'default_parameter', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'min_duration'}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'default_parameter', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'max_loudness'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'default_parameter', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'min_loudness'}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'default_parameter', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'artist_max_familiarity'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'default_parameter', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'artist_min_familiarity'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'default_parameter', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'artist_max_hotttnesss'}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'default_parameter', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'artist_min_hotttnesss'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'default_parameter', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'song_max_hotttnesss'}, {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'default_parameter', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'song_min_hotttnesss'}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'default_parameter', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'default_parameter', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'min_energy'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'default_parameter', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'max_energy'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'default_parameter', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'min_danceability'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'default_parameter', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'max_danceability'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'default_parameter', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'default_parameter', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'max_latitude'}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'default_parameter', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'min_latitude'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'default_parameter', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'max_longitude'}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'default_parameter', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'min_longitude'}; {'id': '96', 'type': 'None', 'children': []}, {'id': '97', 'type': 'default_parameter', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'default_parameter', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'buckets'}; {'id': '102', 'type': 'None', 'children': []}, {'id': '103', 'type': 'default_parameter', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '105', 'type': 'False', 'children': []}; {'id': '106', 'type': 'default_parameter', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'test_new_things'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'default_parameter', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rank_type'}, {'id': '111', 'type': 'None', 'children': []}; {'id': '112', 'type': 'default_parameter', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'artist_start_year_after'}; {'id': '114', 'type': 'None', 'children': []}, {'id': '115', 'type': 'default_parameter', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'artist_start_year_before'}, {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'default_parameter', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'artist_end_year_after'}; {'id': '120', 'type': 'None', 'children': []}, {'id': '121', 'type': 'default_parameter', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'artist_end_year_before'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'default_parameter', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'song_type'}; {'id': '126', 'type': 'None', 'children': []}, {'id': '127', 'type': 'default_parameter', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'min_song_currency'}, {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'default_parameter', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'max_song_currency'}; {'id': '132', 'type': 'None', 'children': []}, {'id': '133', 'type': 'default_parameter', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'min_song_discovery'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'default_parameter', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'max_song_discovery'}; {'id': '138', 'type': 'None', 'children': []}, {'id': '139', 'type': 'default_parameter', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'max_acousticness'}, {'id': '141', 'type': 'None', 'children': []}; {'id': '142', 'type': 'default_parameter', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'min_acousticness'}; {'id': '144', 'type': 'None', 'children': []}, {'id': '145', 'type': 'default_parameter', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'max_liveness'}, {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'default_parameter', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'min_liveness'}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'default_parameter', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'max_speechiness'}, {'id': '153', 'type': 'None', 'children': []}; {'id': '154', 'type': 'default_parameter', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'min_speechiness'}; {'id': '156', 'type': 'None', 'children': []}, {'id': '157', 'type': 'default_parameter', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'max_valence'}, {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'default_parameter', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'min_valence'}; {'id': '162', 'type': 'None', 'children': []}, {'id': '163', 'type': 'block', 'children': ['164', '175', '181', '187', '191', '205']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '167', 'type': 'call', 'children': ['168', '174']}; {'id': '168', 'type': 'attribute', 'children': ['169', '173']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'locals'}; {'id': '180', 'type': 'argument_list', 'children': []}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '186']}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'bucket'"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'buckets'}, {'id': '187', 'type': 'delete_statement', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'buckets'"}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'callm'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '204']}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '%'}; {'id': '200', 'type': 'string', 'children': [], 'value': '"%s/%s"'}, {'id': '201', 'type': 'tuple', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'song'"}, {'id': '203', 'type': 'string', 'children': [], 'value': "'search'"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '205', 'type': 'return_statement', 'children': ['206']}; {'id': '206', 'type': 'list_comprehension', 'children': ['207', '217']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'Song'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'dictionary_splat', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'fix'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 's_dict'}, {'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 's_dict'}, {'id': '219', 'type': 'subscript', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'response'"}, {'id': '223', 'type': 'string', 'children': [], 'value': "'songs'"}
def search(title=None, artist=None, artist_id=None, combined=None, description=None, style=None, mood=None, results=None, start=None, max_tempo=None, min_tempo=None, max_duration=None, min_duration=None, max_loudness=None, min_loudness=None, artist_max_familiarity=None, artist_min_familiarity=None, artist_max_hotttnesss=None, artist_min_hotttnesss=None, song_max_hotttnesss=None, song_min_hotttnesss=None, mode=None, min_energy=None, max_energy=None, min_danceability=None, max_danceability=None, key=None, max_latitude=None, min_latitude=None, max_longitude=None, min_longitude=None, sort=None, buckets=None, limit=False, test_new_things=None, rank_type=None, artist_start_year_after=None, artist_start_year_before=None, artist_end_year_after=None, artist_end_year_before=None,song_type=None,min_song_currency=None,max_song_currency=None, min_song_discovery=None, max_song_discovery=None, max_acousticness=None, min_acousticness=None, max_liveness=None, min_liveness=None, max_speechiness=None, min_speechiness=None, max_valence=None, min_valence=None): limit = str(limit).lower() kwargs = locals() kwargs['bucket'] = buckets del kwargs['buckets'] result = util.callm("%s/%s" % ('song', 'search'), kwargs) return [Song(**util.fix(s_dict)) for s_dict in result['response']['songs']]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_campaigns'}, {'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', '17', '28', '39']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_verify_sort_options'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_verify_filters'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Campaign'}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_get_api'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'update_service'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DefaultApi'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PaginatedResponse'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46', '49']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'update_campaign_list'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'lwrap_type'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Campaign'}, {'id': '49', 'type': 'dictionary_splat', 'children': ['50']}
def list_campaigns(self, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, Campaign, True) api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.update_campaign_list, lwrap_type=Campaign, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_campaign_device_states'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'campaign_id'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '29', '35', '46']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'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': '_verify_sort_options'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'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': '_verify_filters'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'CampaignDeviceState'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"campaign_id"'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'campaign_id'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_get_api'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'update_service'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'DefaultApi'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'PaginatedResponse'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '53', '56']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'update_campaign_metadata_list'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'lwrap_type'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'CampaignDeviceState'}; {'id': '56', 'type': 'dictionary_splat', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def list_campaign_device_states(self, campaign_id, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, CampaignDeviceState, True) kwargs["campaign_id"] = campaign_id api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.update_campaign_metadata_list, lwrap_type=CampaignDeviceState, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_firmware_manifests'}, {'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', '17', '28', '39']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_verify_sort_options'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_verify_filters'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'FirmwareManifest'}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_get_api'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'update_service'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DefaultApi'}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'PaginatedResponse'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46', '49']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'api'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'firmware_manifest_list'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'lwrap_type'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'FirmwareManifest'}, {'id': '49', 'type': 'dictionary_splat', 'children': ['50']}
def list_firmware_manifests(self, **kwargs): kwargs = self._verify_sort_options(kwargs) kwargs = self._verify_filters(kwargs, FirmwareManifest, True) api = self._get_api(update_service.DefaultApi) return PaginatedResponse(api.firmware_manifest_list, lwrap_type=FirmwareManifest, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_bams'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'input_bams'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'merged_bam'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'in_sorted'}, {'id': '9', 'type': 'string', 'children': [], 'value': '"TRUE"'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '30', '43', '73', '87', '98', '114', '126', '130', '136', '145', '149', '153', '162']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22']}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'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': 'input_bams'}, {'id': '21', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '22', 'type': 'block', 'children': ['23', '28']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"No merge required"'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'outdir'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'merged_bam'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '55']}; {'id': '44', 'type': 'boolean_operator', 'children': ['45', '46'], 'value': 'and'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'outdir'}; {'id': '46', 'type': 'not_operator', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'outdir'}, {'id': '55', 'type': 'block', 'children': ['56', '66']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Creating path to merge file\'s folder: \'{}\'"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'outdir'}; {'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': 'os'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'makedirs'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'outdir'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '79']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'in_sorted'}; {'id': '76', 'type': 'list', 'children': ['77', '78'], 'value': '[False, True]'}, {'id': '77', 'type': 'False', 'children': []}; {'id': '78', 'type': 'True', 'children': []}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'in_sorted'}, {'id': '83', 'type': 'conditional_expression', 'children': ['84', '85', '86'], 'value': 'if'}; {'id': '84', 'type': 'string', 'children': [], 'value': '"TRUE"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'in_sorted'}; {'id': '86', 'type': 'string', 'children': [], 'value': '"FALSE"'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}, {'id': '91', 'type': 'string', 'children': [], 'value': '" INPUT="'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': '" INPUT="'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'input_bams'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '109'], 'value': '+'}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '108'], 'value': '+'}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'tools'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'java'}; {'id': '108', 'type': 'string', 'children': [], 'value': '" -Xmx"'}, {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'pm'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'javamem'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'augmented_assignment', 'children': ['116', '117'], 'value': '+='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '125'], 'value': '+'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}, {'id': '119', 'type': 'string', 'children': [], 'value': '" -jar "'}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'picard'}, {'id': '125', 'type': 'string', 'children': [], 'value': '" MergeSamFiles"'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'input_string'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'augmented_assignment', 'children': ['132', '133'], 'value': '+='}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'}; {'id': '134', 'type': 'string', 'children': [], 'value': '" OUTPUT="'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'merged_bam'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'}; {'id': '140', 'type': 'string', 'children': [], 'value': '" ASSUME_SORTED="'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'in_sorted'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '148', 'type': 'string', 'children': [], 'value': '" CREATE_INDEX=TRUE"'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'augmented_assignment', 'children': ['151', '152'], 'value': '+='}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '152', 'type': 'string', 'children': [], 'value': '" VALIDATION_STRINGENCY=SILENT"'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'augmented_assignment', 'children': ['158', '159'], 'value': '+='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'}; {'id': '160', 'type': 'string', 'children': [], 'value': '" TMP_DIR="'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '162', 'type': 'return_statement', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cmd'}
def merge_bams(self, input_bams, merged_bam, in_sorted="TRUE", tmp_dir=None): if not len(input_bams) > 1: print("No merge required") return 0 outdir, _ = os.path.split(merged_bam) if outdir and not os.path.exists(outdir): print("Creating path to merge file's folder: '{}'".format(outdir)) os.makedirs(outdir) if in_sorted in [False, True]: in_sorted = "TRUE" if in_sorted else "FALSE" input_string = " INPUT=" + " INPUT=".join(input_bams) cmd = self.tools.java + " -Xmx" + self.pm.javamem cmd += " -jar " + self.tools.picard + " MergeSamFiles" cmd += input_string cmd += " OUTPUT=" + merged_bam cmd += " ASSUME_SORTED=" + str(in_sorted) cmd += " CREATE_INDEX=TRUE" cmd += " VALIDATION_STRINGENCY=SILENT" if tmp_dir: cmd += " TMP_DIR=" + tmp_dir return cmd
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'samtools_view'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'postpend'}, {'id': '9', 'type': 'string', 'children': [], 'value': '""'}; {'id': '10', 'type': 'block', 'children': ['11', '27']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"{} view {} {} {}"'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '24', '25', '26']}, {'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': 'tools'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'postpend'}, {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'subprocess'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'check_output'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'shell'}
def samtools_view(self, file_name, param, postpend=""): cmd = "{} view {} {} {}".format( self.tools.samtools, param, file_name, postpend) return subprocess.check_output(cmd, shell=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sam_conversions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sam_file'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '34', '64', '84', '117']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '33'], 'value': '+'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '26'], 'value': '+'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '25'], 'value': '+'}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '24'], 'value': '+'}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '23'], 'value': '+'}; {'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': 'tools'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '23', 'type': 'string', 'children': [], 'value': '" view -bS "'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sam_file'}, {'id': '25', 'type': 'string', 'children': [], 'value': '" > "'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sam_file'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '".sam"'}; {'id': '32', 'type': 'string', 'children': [], 'value': '".bam"'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'augmented_assignment', 'children': ['36', '37'], 'value': '+='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '63'], 'value': '+'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '56'], 'value': '+'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '55'], 'value': '+'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '48'], 'value': '+'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '47'], 'value': '+'}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '47', 'type': 'string', 'children': [], 'value': '" sort "'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sam_file'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': '".sam"'}; {'id': '54', 'type': 'string', 'children': [], 'value': '".bam"'}, {'id': '55', 'type': 'string', 'children': [], 'value': '" -o "'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sam_file'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': '".sam"'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}, {'id': '63', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'augmented_assignment', 'children': ['66', '67'], 'value': '+='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '83'], 'value': '+'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '76'], 'value': '+'}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '75'], 'value': '+'}; {'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': 'tools'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '75', 'type': 'string', 'children': [], 'value': '" index "'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sam_file'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': '".sam"'}; {'id': '82', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}, {'id': '83', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'augmented_assignment', 'children': ['89', '90'], 'value': '+='}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '116'], 'value': '+'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '109'], 'value': '+'}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '108'], 'value': '+'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '101'], 'value': '+'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '100'], 'value': '+'}, {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'tools'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '100', 'type': 'string', 'children': [], 'value': '" depth "'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sam_file'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '".sam"'}, {'id': '107', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}; {'id': '108', 'type': 'string', 'children': [], 'value': '" > "'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sam_file'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': '".sam"'}, {'id': '115', 'type': 'string', 'children': [], 'value': '"_sorted.depth"'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '117', 'type': 'return_statement', 'children': ['118']}
def sam_conversions(self, sam_file, depth=True): cmd = self.tools.samtools + " view -bS " + sam_file + " > " + sam_file.replace(".sam", ".bam") + "\n" cmd += self.tools.samtools + " sort " + sam_file.replace(".sam", ".bam") + " -o " + sam_file.replace(".sam", "_sorted.bam") + "\n" cmd += self.tools.samtools + " index " + sam_file.replace(".sam", "_sorted.bam") + "\n" if depth: cmd += self.tools.samtools + " depth " + sam_file.replace(".sam", "_sorted.bam") + " > " + sam_file.replace(".sam", "_sorted.depth") + "\n" return cmd
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bam_conversions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bam_file'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '34', '58', '78', '111']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '33'], 'value': '+'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '26'], 'value': '+'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '25'], 'value': '+'}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '24'], 'value': '+'}, {'id': '17', 'type': 'binary_operator', 'children': ['18', '23'], 'value': '+'}; {'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': 'tools'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '23', 'type': 'string', 'children': [], 'value': '" view -h "'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bam_file'}, {'id': '25', 'type': 'string', 'children': [], 'value': '" > "'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bam_file'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '".bam"'}; {'id': '32', 'type': 'string', 'children': [], 'value': '".sam"'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'augmented_assignment', 'children': ['36', '37'], 'value': '+='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '57'], 'value': '+'}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '50'], 'value': '+'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '49'], 'value': '+'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '48'], 'value': '+'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '47'], 'value': '+'}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '47', 'type': 'string', 'children': [], 'value': '" sort "'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bam_file'}, {'id': '49', 'type': 'string', 'children': [], 'value': '" -o "'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bam_file'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': '".bam"'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}, {'id': '57', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '77'], 'value': '+'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '70'], 'value': '+'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '69'], 'value': '+'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'tools'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'samtools'}, {'id': '69', 'type': 'string', 'children': [], 'value': '" index "'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'bam_file'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'string', 'children': [], 'value': '".bam"'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}, {'id': '77', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '110'], 'value': '+'}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '103'], 'value': '+'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '102'], 'value': '+'}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '95'], 'value': '+'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '94'], 'value': '+'}, {'id': '89', 'type': 'attribute', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tools'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'samtools'}; {'id': '94', 'type': 'string', 'children': [], 'value': '" depth "'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'bam_file'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '".bam"'}, {'id': '101', 'type': 'string', 'children': [], 'value': '"_sorted.bam"'}; {'id': '102', 'type': 'string', 'children': [], 'value': '" > "'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'bam_file'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': '".bam"'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"_sorted.depth"'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '111', 'type': 'return_statement', 'children': ['112']}
def bam_conversions(self, bam_file, depth=True): cmd = self.tools.samtools + " view -h " + bam_file + " > " + bam_file.replace(".bam", ".sam") + "\n" cmd += self.tools.samtools + " sort " + bam_file + " -o " + bam_file.replace(".bam", "_sorted.bam") + "\n" cmd += self.tools.samtools + " index " + bam_file.replace(".bam", "_sorted.bam") + "\n" if depth: cmd += self.tools.samtools + " depth " + bam_file.replace(".bam", "_sorted.bam") + " > " + bam_file.replace(".bam", "_sorted.depth") + "\n" return cmd
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_checkpoint'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '96', '106', '132']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'try_statement', 'children': ['15', '22', '72']}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'is_checkpoint'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'checkpoint'}; {'id': '22', 'type': 'except_clause', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31', '38']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"__call__"'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}, {'id': '39', 'type': 'block', 'children': ['40', '53']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ext'}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'splitext'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '59']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '56'], 'value': 'and'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ext'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'not'}, {'id': '57', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'concatenated_string', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"WARNING: \'{}\' looks like it may be the name or path of "'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"a file; for such a checkpoint, use touch_checkpoint."'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74', '90']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '77']}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'is_checkpoint'}, {'id': '77', 'type': 'block', 'children': ['78', '88']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"Not a checkpoint: {}"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'False', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': '"Checkpointing: \'{}\'"'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '115', '120']}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isabs'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'check_fpath'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '120', 'type': 'else_clause', 'children': ['121']}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'check_fpath'}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'checkpoint_filepath'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pm'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'return_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_touch_checkpoint'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}
def _checkpoint(self, stage): if stage is None: return False try: is_checkpoint = stage.checkpoint except AttributeError: if hasattr(stage, "__call__"): stage = stage.__name__ else: base, ext = os.path.splitext(stage) if ext and "." not in base: print("WARNING: '{}' looks like it may be the name or path of " "a file; for such a checkpoint, use touch_checkpoint.". format(stage)) else: if not is_checkpoint: print("Not a checkpoint: {}".format(stage)) return False stage = stage.name print("Checkpointing: '{}'".format(stage)) if os.path.isabs(stage): check_fpath = stage else: check_fpath = checkpoint_filepath(stage, pm=self) return self._touch_checkpoint(check_fpath)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'geolocation_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'argument'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'unit'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'distance_type'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '76']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'function_name', 'children': [], 'value': 'inner'}; {'id': '16', 'type': 'parameters', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '18', 'type': 'block', 'children': ['19', '33', '52', '63', '74']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'locations'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'getlist'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'argument'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '36', 'type': 'dictionary', 'children': ['37']}, {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'_geo_distance'"}, {'id': '39', 'type': 'dictionary', 'children': ['40', '43', '49']}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'locations'}, {'id': '43', 'type': 'pair', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'order'"}, {'id': '45', 'type': 'conditional_expression', 'children': ['46', '47', '48'], 'value': 'if'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'asc'"}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'desc'"}, {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'unit'"}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'unit'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '62']}, {'id': '57', 'type': 'subscript', 'children': ['58', '61']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'_geo_distance'"}, {'id': '61', 'type': 'string', 'children': [], 'value': "'mode'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'distance_type'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '73']}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'_geo_distance'"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'distance_type'"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'distance_type'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'inner'}
def geolocation_sort(field_name, argument, unit, mode=None, distance_type=None): def inner(asc): locations = request.values.getlist(argument, type=str) field = { '_geo_distance': { field_name: locations, 'order': 'asc' if asc else 'desc', 'unit': unit, } } if mode: field['_geo_distance']['mode'] = mode if distance_type: field['_geo_distance']['distance_type'] = distance_type return field return inner
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eval_field'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '13', '60', '71']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '16', '19']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '19', 'type': 'else_clause', 'children': ['20']}; {'id': '20', 'type': 'block', 'children': ['21', '30', '43', '58']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '33', 'type': 'subscript', 'children': ['34', '42']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '50']}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'order'"}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'reverse_order'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'order'"}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '60', 'type': 'elif_clause', 'children': ['61', '65']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '71', 'type': 'else_clause', 'children': ['72']}; {'id': '72', 'type': 'block', 'children': ['73', '82', '91']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'pattern_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'key_asc'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'parse_sort_field'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '85']}, {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key_asc'}, {'id': '89', 'type': 'not_operator', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'key_asc'}, {'id': '91', 'type': 'return_statement', 'children': ['92']}; {'id': '92', 'type': 'dictionary', 'children': ['93']}, {'id': '93', 'type': 'pair', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '95', 'type': 'dictionary', 'children': ['96']}; {'id': '96', 'type': 'pair', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'order'"}; {'id': '98', 'type': 'conditional_expression', 'children': ['99', '100', '101'], 'value': 'if'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key_asc'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'desc'"}
def eval_field(field, asc): if isinstance(field, dict): if asc: return field else: field = copy.deepcopy(field) key = list(field.keys())[0] field[key]['order'] = reverse_order(field[key]['order']) return field elif callable(field): return field(asc) else: key, key_asc = parse_sort_field(field) if not asc: key_asc = not key_asc return {key: {'order': 'asc' if key_asc else 'desc'}}
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'default_sorter_factory'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '26', '69', '78', '97', '106', '126']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_arg_name'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'urlfield'}; {'id': '14', 'type': 'call', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort_arg_name'}; {'id': '22', 'type': 'string', 'children': [], 'value': "''"}, {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '29']}, {'id': '27', 'type': 'not_operator', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'urlfield'}, {'id': '29', 'type': 'block', 'children': ['30', '46']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'has_query'}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'q'"}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'urlfield'}, {'id': '49', 'type': 'call', 'children': ['50', '63']}; {'id': '50', 'type': 'attribute', 'children': ['51', '62']}, {'id': '51', 'type': 'call', 'children': ['52', '59']}; {'id': '52', 'type': 'attribute', 'children': ['53', '58']}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'RECORDS_REST_DEFAULT_SORT'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '61', 'type': 'dictionary', 'children': []}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '68']}; {'id': '64', 'type': 'conditional_expression', 'children': ['65', '66', '67'], 'value': 'if'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'has_query'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'noquery'"}; {'id': '68', 'type': 'string', 'children': [], 'value': "''"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}, {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'asc'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'parse_sort_field'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'urlfield'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '81', 'type': 'call', 'children': ['82', '95']}; {'id': '82', 'type': 'attribute', 'children': ['83', '94']}, {'id': '83', 'type': 'call', 'children': ['84', '91']}; {'id': '84', 'type': 'attribute', 'children': ['85', '90']}, {'id': '85', 'type': 'subscript', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'RECORDS_REST_SORT_OPTIONS'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '93', 'type': 'dictionary', 'children': []}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_options'}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'tuple', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '105', 'type': 'dictionary', 'children': []}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'list_splat', 'children': ['115']}, {'id': '115', 'type': 'list_comprehension', 'children': ['116', '121']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'eval_field'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sort_options'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'fields'"}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'tuple', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '129', 'type': 'dictionary', 'children': ['130']}; {'id': '130', 'type': 'pair', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sort_arg_name'}
def default_sorter_factory(search, index): sort_arg_name = 'sort' urlfield = request.values.get(sort_arg_name, '', type=str) if not urlfield: has_query = request.values.get('q', type=six.text_type) urlfield = current_app.config['RECORDS_REST_DEFAULT_SORT'].get( index, {}).get('query' if has_query else 'noquery', '') key, asc = parse_sort_field(urlfield) sort_options = current_app.config['RECORDS_REST_SORT_OPTIONS'].get( index, {}).get(key) if sort_options is None: return (search, {}) search = search.sort( *[eval_field(f, asc) for f in sort_options['fields']] ) return (search, {sort_arg_name: urlfield})
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'MakeHistFromList'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9', '18', '29']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Hist'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'list_comprehension', 'children': ['20', '26']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hist'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Incr'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '29', 'type': 'return_statement', 'children': ['30']}
def MakeHistFromList(t, name=''): hist = Hist(name=name) [hist.Incr(x) for x in t] return hist
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'MakePmfFromList'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9', '16', '24', '32', '38']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'MakeHistFromList'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'GetDict'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pmf'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Pmf'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'pmf'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Normalize'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pmf'}
def MakePmfFromList(t, name=''): hist = MakeHistFromList(t) d = hist.GetDict() pmf = Pmf(d, name) pmf.Normalize() return pmf
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'MakeSuiteFromList'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9', '16', '24']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'MakeHistFromList'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hist'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'GetDict'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'MakeSuiteFromDict'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}
def MakeSuiteFromList(t, name=''): hist = MakeHistFromList(t) d = hist.GetDict() return MakeSuiteFromDict(d)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_precursor'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '6', 'type': 'block', 'children': ['7', '59', '75']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'data_loci'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '47']}, {'id': '11', 'type': 'list', 'children': ['12', '13', '18', '26', '34', '39'], 'value': '[x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])]'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'subscript', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'loci'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'strand'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'loci2seq'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '51', 'type': 'argument_list', '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': 'c'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'loci2seq'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'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': 'data_loci'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '72']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'data_loci'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'return_statement', 'children': ['76']}
def sort_precursor(c, loci): data_loci = [[x, loci[x].chr, int(loci[x].start), int(loci[x].end), loci[x].strand, len(c.loci2seq[x])] for x in list(c.loci2seq.keys())] data_loci = sorted(data_loci, key=itemgetter(5), reverse=True) return data_loci
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_merge_similar'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'loci'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'loci_similarity'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '19', '41', '306', '318', '334']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}; {'id': '14', 'type': 'dictionary', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}; {'id': '18', 'type': 'dictionary', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'loci_sorted'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '30', '38']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'loci_similarity'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '40', 'type': 'True', 'children': []}, {'id': '41', 'type': 'for_statement', 'children': ['42', '45', '46']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sim'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'loci_sorted'}; {'id': '46', 'type': 'block', 'children': ['47', '55', '59', '68', '75', '83', '111']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '>'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'similar'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"_merge_similar:try new cluster %s"'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cluster'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}, {'id': '77', 'type': 'pattern_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'p_seen'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'p_unseen'}; {'id': '80', 'type': 'expression_list', 'children': ['81', '82']}, {'id': '81', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'size'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '100']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_get_seqs'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'loci'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_get_seqs'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '113', '294']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '113', 'type': 'block', 'children': ['114', '124', '133', '147', '152', '177', '202', '254']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'consistent'}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_is_consistent'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121', '122', '123']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'loci_similarity'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '%'}, {'id': '131', 'type': 'string', 'children': [], 'value': '"_merge_similar: clusters seen: %s"'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '%'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"_merge_similar: id %s common %s|%s total %s consistent %s"'}, {'id': '141', 'type': 'tuple', 'children': ['142', '143', '144', '145', '146']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sim'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'consistent'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '150']}; {'id': '148', 'type': 'not_operator', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'consistent'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'continue_statement', 'children': []}; {'id': '152', 'type': 'if_statement', 'children': ['153', '158']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': 'in'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}; {'id': '158', 'type': 'block', 'children': ['159', '168']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'p_seen'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'p_unseen'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '176', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '183']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '182'], 'value': 'in'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '183', 'type': 'block', 'children': ['184', '193']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'p_seen'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '192', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'p_unseen'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '202', 'type': 'if_statement', 'children': ['203', '209']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '208'], 'value': '=='}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'p_seen'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '209', 'type': 'block', 'children': ['210', '222', '234', '248']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': '_merge_cluster'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '221']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'new_c'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_merge_cluster'}, {'id': '227', 'type': 'argument_list', 'children': ['228', '233']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'new_c'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'list_comprehension', 'children': ['236', '245']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'dictionary', 'children': ['242']}; {'id': '242', 'type': 'pair', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}, {'id': '245', 'type': 'for_in_clause', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '253']}; {'id': '250', 'type': 'subscript', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'new_c'}; {'id': '254', 'type': 'if_statement', 'children': ['255', '261']}, {'id': '255', 'type': 'comparison_operator', 'children': ['256', '260'], 'value': '=='}; {'id': '256', 'type': 'call', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'p_seen'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '261', 'type': 'block', 'children': ['262', '270', '286']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'idc_seen'}, {'id': '265', 'type': 'subscript', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'p_seen'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '275']}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'idc_seen'}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': '_merge_cluster'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '283']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'p_unseen'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'idc_seen'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '293']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'p_unseen'}; {'id': '292', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'idc_seen'}; {'id': '294', 'type': 'else_clause', 'children': ['295']}, {'id': '295', 'type': 'block', 'children': ['296', '305']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '%'}, {'id': '303', 'type': 'string', 'children': [], 'value': '"_merge_similar: id %s %s are different"'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'pairs'}, {'id': '305', 'type': 'continue_statement', 'children': []}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': '_add_unseen'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316', '317']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'loci'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'clus_seen'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'binary_operator', 'children': ['325', '326'], 'value': '%'}, {'id': '325', 'type': 'string', 'children': [], 'value': '"_merge_similar: total clus %s"'}; {'id': '326', 'type': 'call', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '333', 'type': 'argument_list', 'children': []}; {'id': '334', 'type': 'return_statement', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'internal_cluster'}
def _merge_similar(loci, loci_similarity): n_cluster = 0 internal_cluster = {} clus_seen = {} loci_sorted = sorted(loci_similarity.iteritems(), key=operator.itemgetter(1), reverse=True) for pairs, sim in loci_sorted: common = sim > parameters.similar n_cluster += 1 logger.debug("_merge_similar:try new cluster %s" % n_cluster) new_c = cluster(n_cluster) p_seen, p_unseen = [], [] size = min(len(_get_seqs(loci[pairs[0]])), len(_get_seqs(loci[pairs[1]]))) if common: consistent = _is_consistent(pairs, common, clus_seen, loci_similarity) logger.debug("_merge_similar: clusters seen: %s" % clus_seen) logger.debug("_merge_similar: id %s common %s|%s total %s consistent %s" % (pairs, sim, common, size, consistent)) if not consistent: continue if pairs[0] in clus_seen: p_seen.append(pairs[0]) p_unseen.append(pairs[1]) if pairs[1] in clus_seen: p_seen.append(pairs[1]) p_unseen.append(pairs[0]) if len(p_seen) == 0: new_c = _merge_cluster(loci[pairs[0]], new_c) new_c = _merge_cluster(loci[pairs[1]], new_c) [clus_seen.update({p: n_cluster}) for p in pairs] internal_cluster[n_cluster] = new_c if len(p_seen) == 1: idc_seen = clus_seen[p_seen[0]] internal_cluster[idc_seen] = _merge_cluster(loci[p_unseen[0]], internal_cluster[idc_seen]) clus_seen[p_unseen[0]] = idc_seen else: logger.debug("_merge_similar: id %s %s are different" % pairs) continue internal_cluster.update(_add_unseen(loci, clus_seen, n_cluster)) logger.debug("_merge_similar: total clus %s" % len(internal_cluster.keys())) return internal_cluster
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_solve_loci_deprecated'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'locilen_sorted'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filtered'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'maxseq'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '21', '25', '34', '41', '195', '201']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'first_run'}; {'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': 'seen_seqs'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'augmented_assignment', 'children': ['23', '24'], 'value': '+='}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'logger'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'binary_operator', 'children': ['32', '33'], 'value': '%'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"_solve_loci:new cluster %s"'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cluster'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}, {'id': '41', 'type': 'for_statement', 'children': ['42', '45', '46']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'idl'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'lenl'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'locilen_sorted'}; {'id': '46', 'type': 'block', 'children': ['47', '55', '72', '87', '91', '115', '139']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'locus_seqs'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'loci2seq'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'idl'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'first_run'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'block', 'children': ['60', '64', '68']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'locus_seqs'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'first_run'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'first_idl'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'idl'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'intersect'}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '85']}, {'id': '79', 'type': 'attribute', 'children': ['80', '84']}; {'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': 'seen_seqs'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'intersection'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'locus_seqs'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'common'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'intersect'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '104'], 'value': '/'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '103'], 'value': '*'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'intersect'}, {'id': '103', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '111']}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'locus_seqs'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '%'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"_sole_loci:id %s idl %s len %s max %s seen %s inter %s common %s "'}, {'id': '123', 'type': 'tuple', 'children': ['124', '127', '128', '129', '130', '134', '138']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'idl'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'lenl'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'maxseq'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '145', '184']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '>='}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '*'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'common'}, {'id': '143', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '144', 'type': 'float', 'children': [], 'value': '0.6'}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'if_statement', 'children': ['147', '154', '168']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '151'], 'value': '>='}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '*'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'lenl'}; {'id': '150', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '*'}; {'id': '152', 'type': 'float', 'children': [], 'value': '0.6'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'maxseq'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '161']}, {'id': '157', 'type': 'pattern_list', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'new_c'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': '_merge_loci_in_cluster'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165', '166', '167']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'new_c'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'idl'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '176']}; {'id': '172', 'type': 'pattern_list', 'children': ['173', '174', '175']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': '_merge_with_first_loci'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181', '182', '183']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'first_idl'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'idl'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}; {'id': '184', 'type': 'else_clause', 'children': ['185']}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_remove_seqs_from_loci'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'idl'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'filtered'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'n_cluster'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'new_c'}, {'id': '201', 'type': 'return_statement', 'children': ['202']}; {'id': '202', 'type': 'expression_list', 'children': ['203', '204', '205', '206']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'seen_seqs'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'filtered'}
def _solve_loci_deprecated(c, locilen_sorted, seen_seqs, filtered, maxseq, n_cluster): first_run = 0 seen_seqs = list() n_cluster += 1 logger.debug("_solve_loci:new cluster %s" % n_cluster) new_c = cluster(n_cluster) for idl, lenl in locilen_sorted: locus_seqs = c.loci2seq[idl] if first_run == 0: seen_seqs = locus_seqs first_run = 1 first_idl = idl intersect = list(set(seen_seqs).intersection(locus_seqs)) common = 0 if intersect: common = len(intersect)*1.0/min(len(seen_seqs), len(locus_seqs)) logger.debug("_sole_loci:id %s idl %s len %s max %s seen %s inter %s common %s " % (c.id, idl, lenl, maxseq, len(seen_seqs), len(intersect), common)) if common*1.0 >= 0.6: if lenl*1.0 >= 0.6*maxseq: c, new_c, seen_seqs = _merge_loci_in_cluster(c, new_c, idl, seen_seqs) else: c, new_c, seen_seqs = _merge_with_first_loci(c, new_c, first_idl, idl, seen_seqs) else: c = _remove_seqs_from_loci(c, idl, seen_seqs) filtered[n_cluster] = new_c return c, seen_seqs, filtered, n_cluster
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_prefix_list_checksum'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'threat_list'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '24', '78']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''SELECT value FROM hash_prefix\n WHERE threat_type=? AND platform_type=? AND threat_entry_type=?\n ORDER BY value\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '14', 'type': 'list', 'children': ['15', '18', '21'], 'value': '[threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type]'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'threat_list'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'threat_type'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'threat_list'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'platform_type'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'threat_list'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'threat_entry_type'}; {'id': '24', 'type': 'with_statement', 'children': ['25', '35']}, {'id': '25', 'type': 'with_clause', 'children': ['26']}; {'id': '26', 'type': 'with_item', 'children': ['27']}, {'id': '27', 'type': 'as_pattern', 'children': ['28', '33']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_cursor'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'as_pattern_target', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dbc'}, {'id': '35', 'type': 'block', 'children': ['36', '44', '65']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dbc'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'execute'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'all_hashes'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '51', 'type': 'generator_expression', 'children': ['52', '58']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bytes'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dbc'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'fetchall'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'checksum'}; {'id': '68', 'type': 'call', 'children': ['69', '77']}, {'id': '69', 'type': 'attribute', 'children': ['70', '76']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'hashlib'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sha256'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'all_hashes'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'digest'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'checksum'}
def hash_prefix_list_checksum(self, threat_list): q = '''SELECT value FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? ORDER BY value ''' params = [threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type] with self.get_cursor() as dbc: dbc.execute(q, params) all_hashes = b''.join(bytes(h[0]) for h in dbc.fetchall()) checksum = hashlib.sha256(all_hashes).digest() return checksum
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_hash_prefix_indices'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'threat_list'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '16', '26']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'batch_size'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '40'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'''DELETE FROM hash_prefix\n WHERE threat_type=? AND platform_type=? AND threat_entry_type=? AND value IN ({})\n '''"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'prefixes_to_remove'}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get_hash_prefix_values_to_remove'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'threat_list'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '26', 'type': 'with_statement', 'children': ['27', '37']}, {'id': '27', 'type': 'with_clause', 'children': ['28']}; {'id': '28', 'type': 'with_item', 'children': ['29']}, {'id': '29', 'type': 'as_pattern', 'children': ['30', '35']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_cursor'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'as_pattern_target', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dbc'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '49']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '48']}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'prefixes_to_remove'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'batch_size'}, {'id': '49', 'type': 'block', 'children': ['50', '62', '86']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'remove_batch'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'prefixes_to_remove'}, {'id': '55', 'type': 'slice', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '57', 'type': 'colon', 'children': []}; {'id': '58', 'type': 'parenthesized_expression', 'children': ['59']}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'batch_size'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '76'], 'value': '+'}; {'id': '66', 'type': 'list', 'children': ['67', '70', '73'], 'value': '[\n threat_list.threat_type,\n threat_list.platform_type,\n threat_list.threat_entry_type\n ]'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'threat_list'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'threat_type'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'threat_list'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'platform_type'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'threat_list'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'threat_entry_type'}; {'id': '76', 'type': 'list_comprehension', 'children': ['77', '83']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sqlite3'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'Binary'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'remove_batch'}; {'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': 'dbc'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'execute'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '109']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'q'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': "','"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '105'], 'value': '*'}, {'id': '103', 'type': 'list', 'children': ['104'], 'value': "['?']"}; {'id': '104', 'type': 'string', 'children': [], 'value': "'?'"}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'remove_batch'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}
def remove_hash_prefix_indices(self, threat_list, indices): batch_size = 40 q = '''DELETE FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? AND value IN ({}) ''' prefixes_to_remove = self.get_hash_prefix_values_to_remove(threat_list, indices) with self.get_cursor() as dbc: for i in range(0, len(prefixes_to_remove), batch_size): remove_batch = prefixes_to_remove[i:(i + batch_size)] params = [ threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type ] + [sqlite3.Binary(b) for b in remove_batch] dbc.execute(q.format(','.join(['?'] * len(remove_batch))), params)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'has_equal_value'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ndigits'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'incorrect_msg'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '28', '37', '42', '69', '141']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '21', 'type': 'string', 'children': [], 'value': '"parent"'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': '"You can only use has_equal_value() on the state resulting from check_column, check_row or check_result."'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'incorrect_msg'}, {'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': 'incorrect_msg'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"Column `{{col}}` seems to be incorrect.{{\' Make sure you arranged the rows correctly.\' if ordered else \'\'}}"'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'has_nrows'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '45', '55']}, {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ordered'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'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': 'stu_res'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sol_res'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sort_rows'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '55', 'type': 'else_clause', 'children': ['56']}; {'id': '56', 'type': 'block', 'children': ['57', '63']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'stu_res'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'student_result'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sol_res'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'solution_result'}, {'id': '69', 'type': 'for_statement', 'children': ['70', '73', '78']}; {'id': '70', 'type': 'pattern_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sol_col_name'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sol_col_vals'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sol_res'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79', '85', '111']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'stu_col_vals'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'stu_res'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sol_col_name'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '89']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ndigits'}; {'id': '88', 'type': 'None', 'children': []}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'try_statement', 'children': ['91', '108']}, {'id': '91', 'type': 'block', 'children': ['92', '100']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sol_col_vals'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'round_seq'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sol_col_vals'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ndigits'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'stu_col_vals'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'round_seq'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'stu_col_vals'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ndigits'}; {'id': '108', 'type': 'except_clause', 'children': ['109']}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'pass_statement', 'children': []}, {'id': '111', 'type': 'if_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '!='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sol_col_vals'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'stu_col_vals'}, {'id': '115', 'type': 'block', 'children': ['116', '134']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_msg'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'build_message'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'incorrect_msg'}, {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'fmt_kwargs'}, {'id': '127', 'type': 'dictionary', 'children': ['128', '131']}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': '"col"'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sol_col_name'}, {'id': '131', 'type': 'pair', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': '"ordered"'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ordered'}; {'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': 'state'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'do_test'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_msg'}, {'id': '141', 'type': 'return_statement', 'children': ['142']}
def has_equal_value(state, ordered=False, ndigits=None, incorrect_msg=None): if not hasattr(state, "parent"): raise ValueError( "You can only use has_equal_value() on the state resulting from check_column, check_row or check_result." ) if incorrect_msg is None: incorrect_msg = "Column `{{col}}` seems to be incorrect.{{' Make sure you arranged the rows correctly.' if ordered else ''}}" has_nrows(state) if not ordered: stu_res, sol_res = sort_rows(state) else: stu_res = state.student_result sol_res = state.solution_result for sol_col_name, sol_col_vals in sol_res.items(): stu_col_vals = stu_res[sol_col_name] if ndigits is not None: try: sol_col_vals = round_seq(sol_col_vals, ndigits) stu_col_vals = round_seq(stu_col_vals, ndigits) except: pass if sol_col_vals != stu_col_vals: _msg = state.build_message( incorrect_msg, fmt_kwargs={"col": sol_col_name, "ordered": ordered} ) state.do_test(_msg) return state
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_releases'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '23', '32']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'releases'}, {'id': '9', 'type': 'list_comprehension', 'children': ['10', '18']}; {'id': '10', 'type': 'tuple', 'children': ['11', '17']}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parse_version'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'version'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'releases'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'releases'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'list_comprehension', 'children': ['34', '37']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'release'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'release'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'releases'}
def sorted_releases(self): releases = [(parse_version(release.version), release) for release in self.releases] releases.sort(reverse=True) return [release[1] for release in releases]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_position_stochastic'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '18', '21', '24', '27', '30']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'source_y'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'search_window'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '**'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '15', 'type': 'parenthesized_expression', 'children': ['16']}; {'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'arrival_time_sort'}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'x_center'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'y_center'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'num_random'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '32', 'type': 'False', 'children': []}, {'id': '33', 'type': 'block', 'children': ['34', '42', '161', '174', '192']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '39']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'x_solve'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'y_solve'}, {'id': '39', 'type': 'expression_list', 'children': ['40', '41']}; {'id': '40', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '48']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'num_random'}; {'id': '48', 'type': 'block', 'children': ['49', '68', '87', '98', '122']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'x_init'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '67'], 'value': '+'}, {'id': '53', 'type': 'call', 'children': ['54', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'uniform'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '64']}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '63'], 'value': '/'}, {'id': '61', 'type': 'unary_operator', 'children': ['62'], 'value': '-'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '63', 'type': 'float', 'children': [], 'value': '2.'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '/'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'search_window'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'x_center'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'y_init'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '86'], 'value': '+'}; {'id': '72', 'type': 'call', 'children': ['73', '78']}, {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'uniform'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '83']}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '82'], 'value': '/'}; {'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'search_window'}; {'id': '82', 'type': 'float', 'children': [], 'value': '2.'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '/'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'y_center'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'xinitial'}; {'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': 'array'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'list', 'children': ['96', '97'], 'value': '[x_init, y_init]'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'x_init'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'y_init'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'minimize'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '107', '108', '114', '119']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_root'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'xinitial'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'source_x'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'source_y'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'tol'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '**'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'Nelder-Mead'"}; {'id': '122', 'type': 'if_statement', 'children': ['123', '138']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '135'], 'value': '<'}; {'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': '_root'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '132', '133', '134']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'source_x'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'source_y'}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '**'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '138', 'type': 'block', 'children': ['139', '150']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'x_solve'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'y_solve'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'subscript', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}, {'id': '163', 'type': 'pattern_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'image_util'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'findOverlap'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172', '173']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'x_solve'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'y_solve'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '178']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'is'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'arrival_time_sort'}, {'id': '177', 'type': 'True', 'children': []}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'pattern_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'sort_arrival_times'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190', '191']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'expression_list', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'y_mins'}
def image_position_stochastic(self, source_x, source_y, kwargs_lens, search_window=10, precision_limit=10**(-10), arrival_time_sort=True, x_center=0, y_center=0, num_random=1000, verbose=False): x_solve, y_solve = [], [] for i in range(num_random): x_init = np.random.uniform(-search_window / 2., search_window / 2) + x_center y_init = np.random.uniform(-search_window / 2., search_window / 2) + y_center xinitial = np.array([x_init, y_init]) result = minimize(self._root, xinitial, args=(kwargs_lens, source_x, source_y), tol=precision_limit ** 2, method='Nelder-Mead') if self._root(result.x, kwargs_lens, source_x, source_y) < precision_limit**2: x_solve.append(result.x[0]) y_solve.append(result.x[1]) x_mins, y_mins = image_util.findOverlap(x_solve, y_solve, precision_limit) if arrival_time_sort is True: x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) return x_mins, y_mins
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '42']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'image_position_from_source'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '21', '24', '27', '30', '33', '36', '39']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sourcePos_x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sourcePos_y'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '10', 'type': 'float', 'children': [], 'value': '0.1'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}; {'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '**'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '18', 'type': 'parenthesized_expression', 'children': ['19']}, {'id': '19', 'type': 'unary_operator', 'children': ['20'], 'value': '-'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'num_iter_max'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'arrival_time_sort'}; {'id': '26', 'type': 'True', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'initial_guess_cut'}, {'id': '29', 'type': 'True', 'children': []}; {'id': '30', 'type': 'default_parameter', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '32', 'type': 'False', 'children': []}, {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x_center'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'default_parameter', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'y_center'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '39', 'type': 'default_parameter', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'num_random'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'block', 'children': ['43', '57', '69', '73', '77', '92', '104', '118', '133', '203', '237', '271', '295', '303', '311', '324', '342']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'numPix'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '56'], 'value': '+'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '/'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '56', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '62']}, {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'x_grid'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'y_grid'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'make_grid'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'numPix'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'min_distance'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'augmented_assignment', 'children': ['71', '72'], 'value': '+='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'x_grid'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'x_center'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'augmented_assignment', 'children': ['75', '76'], 'value': '+='}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'y_grid'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'y_center'}, {'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': 'x_mapped'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'y_mapped'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'lensModel'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ray_shooting'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'x_grid'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'y_grid'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'absmapped'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'displaceAbs'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102', '103']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'x_mapped'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'y_mapped'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sourcePos_x'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sourcePos_y'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '110']}; {'id': '106', 'type': 'pattern_list', 'children': ['107', '108', '109']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'delta_map'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'neighborSelect'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116', '117']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'absmapped'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'x_grid'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'y_grid'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '122']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': 'is'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '121', 'type': 'True', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"There are %s regions identified that could contain a solution of the lens equation"'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'initial_guess_cut'}; {'id': '136', 'type': 'True', 'children': []}, {'id': '137', 'type': 'block', 'children': ['138', '156', '164', '176', '188']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'mag'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '152']}, {'id': '147', 'type': 'attribute', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'lensModel'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'magnification'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'mag'}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '<'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'mag'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '<='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'delta_map'}, {'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '*'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '*'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'mag'}, {'id': '175', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '<='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'delta_map'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '*'}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '*'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'mag'}, {'id': '187', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '192']}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '191', 'type': 'True', 'children': []}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"The number of regions that meet the plausibility criteria are %s"'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '212', 'type': 'call', 'children': ['213', '218']}, {'id': '213', 'type': 'attribute', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'uniform'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '227', '234']}, {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'low'}, {'id': '221', 'type': 'binary_operator', 'children': ['222', '226'], 'value': '+'}; {'id': '222', 'type': 'binary_operator', 'children': ['223', '225'], 'value': '/'}, {'id': '223', 'type': 'unary_operator', 'children': ['224'], 'value': '-'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '225', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'x_center'}, {'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'high'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '233'], 'value': '+'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '/'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'search_window'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'x_center'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'num_random'}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '246', 'type': 'call', 'children': ['247', '252']}, {'id': '247', 'type': 'attribute', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'random'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'uniform'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '261', '268']}, {'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'low'}, {'id': '255', 'type': 'binary_operator', 'children': ['256', '260'], 'value': '+'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '259'], 'value': '/'}, {'id': '257', 'type': 'unary_operator', 'children': ['258'], 'value': '-'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'search_window'}, {'id': '259', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'y_center'}, {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'high'}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '267'], 'value': '+'}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '/'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'search_window'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'y_center'}; {'id': '268', 'type': 'keyword_argument', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'num_random'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '277']}, {'id': '273', 'type': 'pattern_list', 'children': ['274', '275', '276']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'solver_precision'}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': '_findIterative'}, {'id': '281', 'type': 'argument_list', 'children': ['282', '283', '284', '285', '286', '287', '288', '289', '292']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'sourcePos_x'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sourcePos_y'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'num_iter_max'}, {'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'min_distance'}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '<='}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'solver_precision'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '306', 'type': 'subscript', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': '<='}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'solver_precision'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'precision_limit'}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '316']}, {'id': '313', 'type': 'pattern_list', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'image_util'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'findOverlap'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322', '323']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'min_distance'}; {'id': '324', 'type': 'if_statement', 'children': ['325', '328']}, {'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': 'is'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'arrival_time_sort'}, {'id': '327', 'type': 'True', 'children': []}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '334']}, {'id': '331', 'type': 'pattern_list', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'y_mins'}; {'id': '334', 'type': 'call', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'sort_arrival_times'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '340', '341']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'x_mins'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'y_mins'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'kwargs_lens'}; {'id': '342', 'type': 'return_statement', 'children': ['343']}, {'id': '343', 'type': 'expression_list', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'x_mins'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'y_mins'}
def image_position_from_source(self, sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, precision_limit=10**(-10), num_iter_max=100, arrival_time_sort=True, initial_guess_cut=True, verbose=False, x_center=0, y_center=0, num_random=0): numPix = int(round(search_window / min_distance) + 0.5) x_grid, y_grid = util.make_grid(numPix, min_distance) x_grid += x_center y_grid += y_center x_mapped, y_mapped = self.lensModel.ray_shooting(x_grid, y_grid, kwargs_lens) absmapped = util.displaceAbs(x_mapped, y_mapped, sourcePos_x, sourcePos_y) x_mins, y_mins, delta_map = util.neighborSelect(absmapped, x_grid, y_grid) if verbose is True: print("There are %s regions identified that could contain a solution of the lens equation" % len(x_mins)) if initial_guess_cut is True: mag = np.abs(self.lensModel.magnification(x_mins, y_mins, kwargs_lens)) mag[mag < 1] = 1 x_mins = x_mins[delta_map <= min_distance*mag*5] y_mins = y_mins[delta_map <= min_distance*mag*5] if verbose is True: print("The number of regions that meet the plausibility criteria are %s" % len(x_mins)) x_mins = np.append(x_mins, np.random.uniform(low=-search_window/2+x_center, high=search_window/2+x_center, size=num_random)) y_mins = np.append(y_mins, np.random.uniform(low=-search_window / 2 + y_center, high=search_window / 2 + y_center, size=num_random)) x_mins, y_mins, solver_precision = self._findIterative(x_mins, y_mins, sourcePos_x, sourcePos_y, kwargs_lens, precision_limit, num_iter_max, verbose=verbose, min_distance=min_distance) x_mins = x_mins[solver_precision <= precision_limit] y_mins = y_mins[solver_precision <= precision_limit] x_mins, y_mins = image_util.findOverlap(x_mins, y_mins, min_distance) if arrival_time_sort is True: x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) return x_mins, y_mins
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'count'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30', '34']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_initialize_client_from_environment'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43', '46', '49', '52', '55', '58', '61', '64']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'event_collection'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'limit'}
def count(event_collection, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.count(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, max_age=max_age, limit=limit)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sum'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'target_property'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31', '35']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_initialize_client_from_environment'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_client'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44', '47', '50', '53', '56', '59', '62', '65', '68']}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'event_collection'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'target_property'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'target_property'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'limit'}
def sum(event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.sum(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, target_property=target_property, max_age=max_age, limit=limit)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'multi_analysis'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'analyses'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'default_parameter', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'default_parameter', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31', '35']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_initialize_client_from_environment'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_client'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'multi_analysis'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '44', '47', '50', '53', '56', '59', '62', '65', '68']}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'event_collection'}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'analyses'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'analyses'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'limit'}
def multi_analysis(event_collection, analyses, timeframe=None, interval=None, timezone=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): _initialize_client_from_environment() return _client.multi_analysis(event_collection=event_collection, timeframe=timeframe, interval=interval, timezone=timezone, filters=filters, group_by=group_by, order_by=order_by, analyses=analyses, max_age=max_age, limit=limit)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_unique'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event_collection'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'target_property'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32', '70']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_params'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '43', '46', '49', '52', '55', '58', '61', '64', '67']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'event_collection'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'event_collection'}, {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'timeframe'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'timeframe'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'timezone'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'timezone'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'interval'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'filters'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'group_by'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'group_by'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'target_property'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'target_property'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'max_age'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'max_age'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'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': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"select_unique"'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'params'}
def select_unique(self, event_collection, target_property, timeframe=None, timezone=None, interval=None, filters=None, group_by=None, order_by=None, max_age=None, limit=None): params = self.get_params(event_collection=event_collection, timeframe=timeframe, timezone=timezone, interval=interval, filters=filters, group_by=group_by, order_by=order_by, target_property=target_property, max_age=max_age, limit=limit) return self.api.query("select_unique", params)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_voltage'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '136', '154']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'if_statement', 'children': ['12', '15', '129']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': '=='}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'MV'"}, {'id': '15', 'type': 'block', 'children': ['16', '29', '42', '50']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'mv_max_v_level_lc_diff_normal'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cfg_ding0'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'mv_routing_tech_constraints'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'mv_max_v_level_lc_diff_normal'"}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'mv_max_v_level_fc_diff_normal'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cfg_ding0'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'mv_routing_tech_constraints'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'mv_max_v_level_fc_diff_normal'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'voltage_station'}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_station'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'voltage_res'}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '57']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'graph_nodes_sorted'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'try_statement', 'children': ['59', '126']}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '93']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '77', '78'], 'value': 'or'}; {'id': '62', 'type': 'parenthesized_expression', 'children': ['63']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '76'], 'value': '>'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '71'], 'value': '-'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'voltage_station'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'voltage_res'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'mv_max_v_level_lc_diff_normal'}, {'id': '77', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '78', 'type': 'parenthesized_expression', 'children': ['79']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '92'], 'value': '>'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '87'], 'value': '-'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'voltage_station'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'voltage_res'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'mv_max_v_level_fc_diff_normal'}, {'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': 'crit_nodes'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '99', 'type': 'dictionary', 'children': ['100', '103']}; {'id': '100', 'type': 'pair', 'children': ['101', '102']}, {'id': '101', 'type': 'string', 'children': [], 'value': "'node'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '103', 'type': 'pair', 'children': ['104', '105']}; {'id': '104', 'type': 'string', 'children': [], 'value': "'v_diff'"}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'list_comprehension', 'children': ['109', '115']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '-'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'v2'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v1'}, {'id': '115', 'type': 'for_in_clause', 'children': ['116', '119']}; {'id': '116', 'type': 'pattern_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'v1'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'v2'}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'voltage_res'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'voltage_station'}; {'id': '126', 'type': 'except_clause', 'children': ['127']}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'pass_statement', 'children': []}, {'id': '129', 'type': 'elif_clause', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '=='}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'LV'"}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'raise_statement', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'==> {} nodes have voltage issues.'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'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': 'crit_nodes'}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'list_comprehension', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'node'"}, {'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '169', '177']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '171', 'type': 'lambda', 'children': ['172', '174']}; {'id': '172', 'type': 'lambda_parameters', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'v_diff'"}, {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '179', 'type': 'True', 'children': []}
def check_voltage(grid, mode): crit_nodes = {} if mode == 'MV': mv_max_v_level_lc_diff_normal = float(cfg_ding0.get('mv_routing_tech_constraints', 'mv_max_v_level_lc_diff_normal')) mv_max_v_level_fc_diff_normal = float(cfg_ding0.get('mv_routing_tech_constraints', 'mv_max_v_level_fc_diff_normal')) voltage_station = grid._station.voltage_res for node in grid.graph_nodes_sorted(): try: if (abs(voltage_station[0] - node.voltage_res[0]) > mv_max_v_level_lc_diff_normal) or\ (abs(voltage_station[1] - node.voltage_res[1]) > mv_max_v_level_fc_diff_normal): crit_nodes[node] = {'node': node, 'v_diff': max([abs(v2-v1) for v1, v2 in zip(node.voltage_res, voltage_station)])} except: pass elif mode == 'LV': raise NotImplementedError if crit_nodes: logger.info('==> {} nodes have voltage issues.'.format(len(crit_nodes))) return [_['node'] for _ in sorted(crit_nodes.values(), key=lambda _: _['v_diff'], reverse=True)]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_savings_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '100', '125']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'savings_list'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'for_statement', 'children': ['12', '15', '20']}; {'id': '12', 'type': 'pattern_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'edges'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '46', '64']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '31', '38']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '<'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '35', 'type': 'tuple', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '38', 'type': 'else_clause', 'children': ['39']}, {'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': 't'}, {'id': '43', 'type': 'tuple', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '62']}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '55'], 'value': 'or'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'depot'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'depot'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'continue_statement', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'savings_list'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '93'], 'value': '-'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '82'], 'value': '+'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'distance'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '81']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'depot'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'distance'}; {'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': 'graph'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'depot'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'distance'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sorted_savings_list'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '114', '122']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'savings_list'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '124', 'type': 'True', 'children': []}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'list_comprehension', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '132']}, {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'saving'}
def compute_savings_list(self, graph): savings_list = {} for i, j in graph.edges(): if repr(i) < repr(j): t = (i, j) else: t = (j, i) if i == graph.depot() or j == graph.depot(): continue savings_list[t] = graph.distance(graph.depot(), i) + graph.distance(graph.depot(), j) - graph.distance(i, j) sorted_savings_list = sorted(list(savings_list.items()), key=operator.itemgetter(1), reverse=True) return [nodes for nodes, saving in sorted_savings_list]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'ask_choice'}, {'id': '3', 'type': 'parameters', 'children': ['4', '9', '17']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '7']}, {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'prompt'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Token'}, {'id': '9', 'type': 'typed_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '14', 'type': 'type_parameter', 'children': ['15']}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '25']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'func_desc'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'generic_type', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '22', 'type': 'type_parameter', 'children': ['23']}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'FuncDesc'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'type', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '28', 'type': 'block', 'children': ['29', '44', '51', '57', '66', '96', '100', '104', '173']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'func_desc'}; {'id': '32', 'type': 'None', 'children': []}, {'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': 'func_desc'}, {'id': '37', 'type': 'lambda', 'children': ['38', '40']}; {'id': '38', 'type': 'lambda_parameters', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tokens'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_ask_tokens'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'prompt'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'list_splat', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'tokens'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'func_desc'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '70', '77']}, {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '77', 'type': 'block', 'children': ['78', '85']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'choice_desc'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'func_desc'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'choice'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91', '94', '95']}, {'id': '89', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'blue'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '%'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"%i"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'reset'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'choice_desc'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'keep_asking'}, {'id': '99', 'type': 'True', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'while_statement', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'keep_asking'}; {'id': '106', 'type': 'block', 'children': ['107', '113', '119', '137', '161', '169']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'read_input'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'if_statement', 'children': ['114', '116']}; {'id': '114', 'type': 'not_operator', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'None', 'children': []}, {'id': '119', 'type': 'try_statement', 'children': ['120', '128']}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '128', 'type': 'except_clause', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '130', 'type': 'block', 'children': ['131', '136']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"Please enter a valid number"'}; {'id': '136', 'type': 'continue_statement', 'children': []}, {'id': '137', 'type': 'if_statement', 'children': ['138', '150']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'not'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}, {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '149'], 'value': '+'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'choices'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'block', 'children': ['151', '160']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '159']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"is out of range"'}; {'id': '160', 'type': 'continue_statement', 'children': []}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'choices'}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '-'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'keep_asking'}; {'id': '172', 'type': 'False', 'children': []}, {'id': '173', 'type': 'return_statement', 'children': ['174']}
def ask_choice( *prompt: Token, choices: List[Any], func_desc: Optional[FuncDesc] = None ) -> Any: if func_desc is None: func_desc = lambda x: str(x) tokens = get_ask_tokens(prompt) info(*tokens) choices.sort(key=func_desc) for i, choice in enumerate(choices, start=1): choice_desc = func_desc(choice) info(" ", blue, "%i" % i, reset, choice_desc) keep_asking = True res = None while keep_asking: answer = read_input() if not answer: return None try: index = int(answer) except ValueError: info("Please enter a valid number") continue if index not in range(1, len(choices) + 1): info(str(index), "is out of range") continue res = choices[index - 1] keep_asking = False return res
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '35', '52']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'backups'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '22']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'backup_directory'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'backups'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'WorkspaceBackup'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'from_path'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'd'}, {'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': 'backups'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '49']}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '43', 'type': 'lambda', 'children': ['44', '46']}; {'id': '44', 'type': 'lambda_parameters', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'lastmod'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '51', 'type': 'True', 'children': []}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'backups'}
def list(self): backups = [] for d in glob(join(self.backup_directory, '*')): backups.append(WorkspaceBackup.from_path(d)) backups.sort(key=lambda b: b.lastmod, reverse=True) return backups
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'retrieve'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '20', '40']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_get'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Mark'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '34', '37']}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'collection'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'operation'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'operation'}, {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Mark'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'from_dict'}, {'id': '45', 'type': 'argument_list', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'}
def retrieve(self, operation, field=None): obj = self._get(operation, field) if obj is None: return Mark(collection=self.collection, operation=operation, field=field) return Mark.from_dict(self.collection, obj)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'criteria'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'distinct_key'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'block', 'children': ['17', '43', '52', '69', '87']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21', '33']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '27']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}, {'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': '_parse_properties'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '33', 'type': 'else_clause', 'children': ['34']}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}; {'id': '40', 'type': 'expression_list', 'children': ['41', '42']}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'crit'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_parse_criteria'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'criteria'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'query_post'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '62']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'query_post'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'crit'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '72', 'type': 'call', 'children': ['73', '78']}, {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'collection'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '82', '85']}, {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'crit'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'projection'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '85', 'type': 'dictionary_splat', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '91', '112']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'distinct_key'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'block', 'children': ['92', '101']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'distinct'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'distinct_key'}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'QueryListResults'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106', '107']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cur'}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'postprocess'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'result_post'}; {'id': '112', 'type': 'else_clause', 'children': ['113']}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'QueryResults'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'prop_dict'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'postprocess'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}
def query(self, properties=None, criteria=None, distinct_key=None, **kwargs): if properties is not None: props, prop_dict = self._parse_properties(properties) else: props, prop_dict = None, None crit = self._parse_criteria(criteria) if self.query_post: for func in self.query_post: func(crit, props) cur = self.collection.find(filter=crit, projection=props, **kwargs) if distinct_key is not None: cur = cur.distinct(distinct_key) return QueryListResults(prop_dict, cur, postprocess=self.result_post) else: return QueryResults(prop_dict, cur, postprocess=self.result_post)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_rows'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '7', 'type': 'block', 'children': ['8', '35']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '22', '29']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '15'], 'value': '=='}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'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': 'Differ'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'CHANGED'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Differ'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'CHANGED_DELTA'}, {'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': 'sort_key'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_key'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_key'}
def sort_rows(self, rows, section): if section.lower() == Differ.CHANGED.lower(): sort_key = Differ.CHANGED_DELTA else: sort_key = None if sort_key is not None: rows.sort(key=itemgetter(sort_key))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_free_crypto_domains'}, {'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': 'crypto_adapters'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '27', '33', '37', '64', '70', '83', '155', '166', '172']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'crypto_adapters'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'crypto_adapters'}, {'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': 'adapters'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'findall'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'crypto'"}, {'id': '27', 'type': 'if_statement', 'children': ['28', '30']}; {'id': '28', 'type': 'not_operator', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'crypto_adapters'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'None', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'max_domains'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ca'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'crypto_adapters'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '45', '52']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_domains'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'max_domains'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ca'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'maximum_crypto_domains'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'max_domains'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ca'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'maximum_crypto_domains'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'max_domains'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'used_domains'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'partitions'}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'partitions'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'full_properties'}; {'id': '82', 'type': 'True', 'children': []}, {'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'partition'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'partitions'}; {'id': '86', 'type': 'block', 'children': ['87', '96']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'crypto_config'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'partition'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_property'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'crypto-configuration'"}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'crypto_config'}; {'id': '98', 'type': 'block', 'children': ['99', '105', '111']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'adapter_uris'}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'crypto_config'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'crypto-adapter-uris'"}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'domain_configs'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'crypto_config'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'crypto-domain-configurations'"}, {'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ca'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'crypto_adapters'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'if_statement', 'children': ['116', '121']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': 'in'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ca'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'adapter_uris'}, {'id': '121', 'type': 'block', 'children': ['122', '128', '148']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'used_adapter_domains'}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '127', 'type': 'argument_list', 'children': []}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'domain_configs'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '=='}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dc'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'access-mode'"}, {'id': '137', 'type': 'string', 'children': [], 'value': "'control-usage'"}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'used_adapter_domains'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dc'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'domain-index'"}; {'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': 'used_domains'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'used_adapter_domains'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'all_domains'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'max_domains'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'free_domains'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '-'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'all_domains'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'used_domains'}; {'id': '172', 'type': 'return_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'free_domains'}
def get_free_crypto_domains(self, crypto_adapters=None): if crypto_adapters is None: crypto_adapters = self.adapters.findall(type='crypto') if not crypto_adapters: return None max_domains = None for ca in crypto_adapters: if max_domains is None: max_domains = ca.maximum_crypto_domains else: max_domains = min(ca.maximum_crypto_domains, max_domains) used_domains = set() partitions = self.partitions.list(full_properties=True) for partition in partitions: crypto_config = partition.get_property('crypto-configuration') if crypto_config: adapter_uris = crypto_config['crypto-adapter-uris'] domain_configs = crypto_config['crypto-domain-configurations'] for ca in crypto_adapters: if ca.uri in adapter_uris: used_adapter_domains = list() for dc in domain_configs: if dc['access-mode'] == 'control-usage': used_adapter_domains.append(dc['domain-index']) used_domains.update(used_adapter_domains) all_domains = set(range(0, max_domains)) free_domains = all_domains - used_domains return sorted(list(free_domains))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'topological'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '5', 'type': 'block', 'children': ['6', '21', '93', '105']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '12']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'enter'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '12', 'type': 'expression_list', 'children': ['13', '16', '20']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'deque'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '20', 'type': 'dictionary', 'children': []}, {'id': '21', 'type': 'function_definition', 'children': ['22', '23', '25']}; {'id': '22', 'type': 'function_name', 'children': [], 'value': 'dfs'}, {'id': '23', 'type': 'parameters', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '25', 'type': 'block', 'children': ['26', '32', '80', '87']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'GRAY'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '41']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '40', 'type': 'tuple', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42', '52', '62', '68', '75']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'GRAY'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'BLACK'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'continue_statement', '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': 'enter'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'discard'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dfs'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'appendleft'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'BLACK'}, {'id': '93', 'type': 'while_statement', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'enter'}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dfs'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'enter'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'return_statement', 'children': ['106']}
def topological(nodes): order, enter, state = deque(), set(nodes), {} def dfs(node): state[node] = GRAY for parent in nodes.get(node, ()): color = state.get(parent, None) if color == GRAY: raise ValueError('cycle') if color == BLACK: continue enter.discard(parent) dfs(parent) order.appendleft(node) state[node] = BLACK while enter: dfs(enter.pop()) return order
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_teachers_sorted'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '31', '65', '92', '110', '120', '142', '148', '175']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'teachers'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_teachers'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'teachers'}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '28']}; {'id': '18', 'type': 'tuple', 'children': ['19', '22', '25']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'last_name'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'first_name'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'teachers'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'teachers'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '57']}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '52'], 'value': 'or'}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '47'], 'value': 'or'}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'is'}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': 'is'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': 'is'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'teachers'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'teachers'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'if_statement', 'children': ['70', '84']}; {'id': '70', 'type': 'boolean_operator', 'children': ['71', '76'], 'value': 'or'}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '75'], 'value': 'is'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '83'], 'value': '<='}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'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': 'teachers'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 't'}; {'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': 'teachers'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'lambda', 'children': ['101', '103']}, {'id': '101', 'type': 'lambda_parameters', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '103', 'type': 'tuple', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'id_list'}, {'id': '113', 'type': 'list_comprehension', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'teachers'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'clauses'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'list_comprehension', 'children': ['129', '134']}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'WHEN id=%s THEN %s'"}, {'id': '131', 'type': 'tuple', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'pk'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '138']}, {'id': '135', 'type': 'pattern_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'id_list'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '%'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'CASE %s END'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'clauses'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'queryset'}, {'id': '151', 'type': 'call', 'children': ['152', '164']}; {'id': '152', 'type': 'attribute', 'children': ['153', '163']}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'User'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'filter'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'id__in'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'id_list'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'extra'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '171']}, {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'select'}, {'id': '167', 'type': 'dictionary', 'children': ['168']}; {'id': '168', 'type': 'pair', 'children': ['169', '170']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'ordering'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ordering'}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '173', 'type': 'tuple', 'children': ['174']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'ordering'"}, {'id': '175', 'type': 'return_statement', 'children': ['176']}
def get_teachers_sorted(self): teachers = self.get_teachers() teachers = [(u.last_name, u.first_name, u.id) for u in teachers] for t in teachers: if t is None or t[0] is None or t[1] is None or t[2] is None: teachers.remove(t) for t in teachers: if t[0] is None or len(t[0]) <= 1: teachers.remove(t) teachers.sort(key=lambda u: (u[0], u[1])) id_list = [t[2] for t in teachers] clauses = ' '.join(['WHEN id=%s THEN %s' % (pk, i) for i, pk in enumerate(id_list)]) ordering = 'CASE %s END' % clauses queryset = User.objects.filter(id__in=id_list).extra(select={'ordering': ordering}, order_by=('ordering',)) return queryset
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_bits'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'generic_type', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '8', 'type': 'type_parameter', 'children': ['9']}, {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'generic_type', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '12', 'type': 'type_parameter', 'children': ['13', '15']}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '29']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'bit'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'lambda', 'children': ['32', '34']}; {'id': '32', 'type': 'lambda_parameters', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}
def sorted_bits(self) -> List[Tuple[str, int]]: return sorted(self.bit.items(), key=lambda x: x[1])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_enums'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'type', 'children': ['6']}; {'id': '6', 'type': 'generic_type', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '8', 'type': 'type_parameter', 'children': ['9']}, {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'generic_type', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '12', 'type': 'type_parameter', 'children': ['13', '15']}, {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '29']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'enum'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '31', 'type': 'lambda', 'children': ['32', '34']}; {'id': '32', 'type': 'lambda_parameters', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}
def sorted_enums(self) -> List[Tuple[str, int]]: return sorted(self.enum.items(), key=lambda x: x[1])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '22', '32', '39', '52', '56', '60', '99', '114']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '18', 'type': 'lambda', 'children': ['19', '21']}, {'id': '19', 'type': 'lambda_parameters', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'reverse'"}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'min_or_max'}, {'id': '35', 'type': 'conditional_expression', 'children': ['36', '37', '38'], 'value': 'if'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '42', 'type': 'list_comprehension', 'children': ['43', '47', '50']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'iter'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'iterable'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'iterables'}; {'id': '50', 'type': 'if_clause', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'iterable'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'next_values'}, {'id': '55', 'type': 'dictionary', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'by_key'}, {'id': '59', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '60', 'type': 'function_definition', 'children': ['61', '62', '65']}, {'id': '61', 'type': 'function_name', 'children': [], 'value': 'gather_next_value'}; {'id': '62', 'type': 'parameters', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'try_statement', 'children': ['67', '75', '79']}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'next_value'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '75', 'type': 'except_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'pass_statement', 'children': []}, {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81', '87']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'next_values'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'next_value'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'by_key'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'tuple', 'children': ['94', '98']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'next_value'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '99', 'type': 'for_statement', 'children': ['100', '103', '107']}; {'id': '100', 'type': 'pattern_list', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'gather_next_value'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '114', 'type': 'while_statement', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'by_key'}; {'id': '116', 'type': 'block', 'children': ['117', '126', '135', '144', '147']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'pattern_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'key_value'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'min_or_max'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'by_key'}; {'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': 'by_key'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'tuple', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'key_value'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'next_value'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'next_values'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'yield', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'next_value'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'gather_next_value'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '154']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'index'}
def collate(*iterables, **kwargs): key = kwargs.pop('key', lambda a: a) reverse = kwargs.pop('reverse', False) min_or_max = max if reverse else min rows = [iter(iterable) for iterable in iterables if iterable] next_values = {} by_key = [] def gather_next_value(row, index): try: next_value = next(row) except StopIteration: pass else: next_values[index] = next_value by_key.append((key(next_value), index)) for index, row in enumerate(rows): gather_next_value(row, index) while by_key: key_value, index = min_or_max(by_key) by_key.remove((key_value, index)) next_value = next_values.pop(index) yield next_value gather_next_value(rows[index], index)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_key_defs'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'key_def'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '60', '72']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': '_int'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kd'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'key_def'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '23', '51']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '22'], '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': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kd'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'use'"}; {'id': '22', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_use'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kd'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'use'"}, {'id': '29', 'type': 'block', 'children': ['30', '38', '44']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_kd'}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'kd'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_kd'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'use'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_use'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_int'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_kd'}, {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'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': '_int'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'kd'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_int'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort_func'}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_int'}
def order_key_defs(key_def): _int = [] for kd in key_def: if len(kd['use']) > 1: for _use in kd['use']: _kd = kd.copy() _kd['use'] = _use _int.append(_kd) else: _int.append(kd) _int.sort(key=cmp_to_key(sort_func)) return _int
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'condition_or_value'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '32', '50', '62', '68', '81', '145', '155', '166']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '26']}, {'id': '11', 'type': 'parenthesized_expression', 'children': ['12']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '20'], 'value': 'and'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'condition_or_value'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'collections'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'Sequence'}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'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': 'condition_or_value'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'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': 'NotImplementedError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'Currently only single conditions are supported'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'condition_test'}, {'id': '35', 'type': 'parenthesized_expression', 'children': ['36']}; {'id': '36', 'type': 'conditional_expression', 'children': ['37', '38', '42'], 'value': 'if'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'condition_or_value'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'condition_or_value'}; {'id': '42', 'type': 'lambda', 'children': ['43', '45']}, {'id': '43', 'type': 'lambda_parameters', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': '=='}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'condition_or_value'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ioloop'}, {'id': '53', 'type': 'call', 'children': ['54', '61']}; {'id': '54', 'type': 'attribute', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tornado'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ioloop'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'IOLoop'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'current'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Future'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '75']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sampling_strategy'}, {'id': '73', 'type': 'tuple', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'none'"}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'raise_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'KATCPSensorError'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': "'Cannot wait on a sensor that does not have a strategy set'"}, {'id': '81', 'type': 'function_definition', 'children': ['82', '83', '86']}; {'id': '82', 'type': 'function_name', 'children': [], 'value': 'handle_update'}, {'id': '83', 'type': 'parameters', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sensor'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'reading'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'try_statement', 'children': ['88', '124']}; {'id': '88', 'type': 'block', 'children': ['89', '93']}, {'id': '89', 'type': 'assert_statement', 'children': ['90']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sensor'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '98']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'condition_test'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'reading'}; {'id': '98', 'type': 'block', 'children': ['99', '106']}, {'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': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'unregister_listener'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'handle_update'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '113']}, {'id': '107', 'type': 'not_operator', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'done'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'block', 'children': ['114']}; {'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': 'ioloop'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'add_callback'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'set_result'}, {'id': '123', 'type': 'True', 'children': []}; {'id': '124', 'type': 'except_clause', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '126', 'type': 'block', 'children': ['127', '138']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'set_exc_info'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'exc_info'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'unregister_listener'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'handle_update'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'register_listener'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'handle_update'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'reading'}; {'id': '154', 'type': 'True', 'children': []}, {'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': 'ioloop'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'add_callback'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'handle_update'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': '_reading'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '168', '204']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '168', 'type': 'block', 'children': ['169', '179', '187', '202']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '178'], 'value': '+'}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ioloop'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'timeout_f'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'with_timeout'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'timeout_f'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'add_done_callback'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'lambda', 'children': ['194', '196']}; {'id': '194', 'type': 'lambda_parameters', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'unregister_listener'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'handle_update'}; {'id': '202', 'type': 'return_statement', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'timeout_f'}; {'id': '204', 'type': 'else_clause', 'children': ['205']}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'return_statement', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'f'}
def wait(self, condition_or_value, timeout=None): if (isinstance(condition_or_value, collections.Sequence) and not isinstance(condition_or_value, basestring)): raise NotImplementedError( 'Currently only single conditions are supported') condition_test = (condition_or_value if callable(condition_or_value) else lambda s: s.value == condition_or_value) ioloop = tornado.ioloop.IOLoop.current() f = Future() if self.sampling_strategy == ('none', ): raise KATCPSensorError( 'Cannot wait on a sensor that does not have a strategy set') def handle_update(sensor, reading): try: assert sensor is self if condition_test(reading): self.unregister_listener(handle_update) if not f.done(): ioloop.add_callback(f.set_result, True) except Exception: f.set_exc_info(sys.exc_info()) self.unregister_listener(handle_update) self.register_listener(handle_update, reading=True) ioloop.add_callback(handle_update, self, self._reading) if timeout: to = ioloop.time() + timeout timeout_f = with_timeout(to, f) timeout_f.add_done_callback( lambda f: self.unregister_listener(handle_update)) return timeout_f else: return f
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_nearest_conn_objects'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'branches'}, {'id': '7', 'type': 'block', 'children': ['8', '18', '22', '35', '243', '262']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'conn_diff_tolerance'}, {'id': '11', 'type': 'subscript', 'children': ['12', '17']}; {'id': '12', 'type': 'subscript', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'grid_connection'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'conn_diff_tolerance'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min_stack'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'node_shp'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'transform'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '32']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'proj2equidistant'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'branch'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '38', 'type': 'block', 'children': ['39', '45', '60', '75', '84', '147', '187', '217', '236']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'branch'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'adj_nodes'"}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'station1_shp'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'transform'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '55']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'proj2equidistant'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'station2_shp'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'transform'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '70']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'proj2equidistant'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'stations'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'line_shp'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'LineString'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'list', 'children': ['82', '83'], 'value': '[station1_shp, station2_shp]'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'station1_shp'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'station2_shp'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}, {'id': '87', 'type': 'dictionary', 'children': ['88', '109', '130']}; {'id': '88', 'type': 'pair', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'s1'"}; {'id': '90', 'type': 'dictionary', 'children': ['91', '96', '99']}, {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'obj'"}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'stations'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'pair', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'shp'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'station1_shp'}, {'id': '99', 'type': 'pair', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'dist'"}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '108'], 'value': '*'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'node_shp'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'distance'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'station1_shp'}; {'id': '108', 'type': 'float', 'children': [], 'value': '0.999'}, {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'s2'"}, {'id': '111', 'type': 'dictionary', 'children': ['112', '117', '120']}; {'id': '112', 'type': 'pair', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'obj'"}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stations'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'pair', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "'shp'"}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'station2_shp'}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'dist'"}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '129'], 'value': '*'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'node_shp'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'distance'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'station2_shp'}, {'id': '129', 'type': 'float', 'children': [], 'value': '0.999'}; {'id': '130', 'type': 'pair', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '132', 'type': 'dictionary', 'children': ['133', '136', '139']}, {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'obj'"}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'branch'}; {'id': '136', 'type': 'pair', 'children': ['137', '138']}, {'id': '137', 'type': 'string', 'children': [], 'value': "'shp'"}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'line_shp'}, {'id': '139', 'type': 'pair', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'dist'"}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'node_shp'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'distance'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'line_shp'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '182']}; {'id': '148', 'type': 'parenthesized_expression', 'children': ['149']}, {'id': '149', 'type': 'boolean_operator', 'children': ['150', '166'], 'value': 'or'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '165'], 'value': '<'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '160'], 'value': '-'}, {'id': '155', 'type': 'subscript', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'s1'"}, {'id': '159', 'type': 'string', 'children': [], 'value': "'dist'"}; {'id': '160', 'type': 'subscript', 'children': ['161', '164']}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '164', 'type': 'string', 'children': [], 'value': "'dist'"}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'conn_diff_tolerance'}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '181'], 'value': '<'}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '176'], 'value': '-'}, {'id': '171', 'type': 'subscript', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'s2'"}, {'id': '175', 'type': 'string', 'children': [], 'value': "'dist'"}; {'id': '176', 'type': 'subscript', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '180', 'type': 'string', 'children': [], 'value': "'dist'"}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'conn_diff_tolerance'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'delete_statement', 'children': ['184']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'b'"}, {'id': '187', 'type': 'if_statement', 'children': ['188', '197', '202']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '196']}, {'id': '191', 'type': 'subscript', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'s1'"}, {'id': '195', 'type': 'string', 'children': [], 'value': "'obj'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'MVStation'}, {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'delete_statement', 'children': ['199']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'s1'"}; {'id': '202', 'type': 'elif_clause', 'children': ['203', '212']}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '211']}; {'id': '206', 'type': 'subscript', 'children': ['207', '210']}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'s2'"}; {'id': '210', 'type': 'string', 'children': [], 'value': "'obj'"}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'MVStation'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'delete_statement', 'children': ['214']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'s2'"}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '228']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'conn_objects'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '227', 'type': 'argument_list', 'children': []}; {'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '230', 'type': 'lambda', 'children': ['231', '233']}, {'id': '231', 'type': 'lambda_parameters', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '235', 'type': 'string', 'children': [], 'value': "'dist'"}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min_stack'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min_stack'}; {'id': '246', 'type': 'list_comprehension', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '248', 'type': 'for_in_clause', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min_stack'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '256', 'type': 'lambda', 'children': ['257', '259']}, {'id': '257', 'type': 'lambda_parameters', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'dist'"}; {'id': '262', 'type': 'return_statement', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'conn_objects_min_stack'}
def _find_nearest_conn_objects(network, node, branches): conn_diff_tolerance = network.config['grid_connection'][ 'conn_diff_tolerance'] conn_objects_min_stack = [] node_shp = transform(proj2equidistant(network), node.geom) for branch in branches: stations = branch['adj_nodes'] station1_shp = transform(proj2equidistant(network), stations[0].geom) station2_shp = transform(proj2equidistant(network), stations[1].geom) line_shp = LineString([station1_shp, station2_shp]) conn_objects = {'s1': {'obj': stations[0], 'shp': station1_shp, 'dist': node_shp.distance(station1_shp) * 0.999}, 's2': {'obj': stations[1], 'shp': station2_shp, 'dist': node_shp.distance(station2_shp) * 0.999}, 'b': {'obj': branch, 'shp': line_shp, 'dist': node_shp.distance(line_shp)}} if ( abs(conn_objects['s1']['dist'] - conn_objects['b']['dist']) < conn_diff_tolerance or abs(conn_objects['s2']['dist'] - conn_objects['b']['dist']) < conn_diff_tolerance ): del conn_objects['b'] if isinstance(conn_objects['s1']['obj'], MVStation): del conn_objects['s1'] elif isinstance(conn_objects['s2']['obj'], MVStation): del conn_objects['s2'] conn_objects_min = min(conn_objects.values(), key=lambda v: v['dist']) conn_objects_min_stack.append(conn_objects_min) conn_objects_min_stack = [_ for _ in sorted(conn_objects_min_stack, key=lambda x: x['dist'])] return conn_objects_min_stack
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mv_voltage_deviation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'voltage_levels'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'mv_lv'"}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '23', '29', '39', '49', '147', '173', '199', '211', '224', '278']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}; {'id': '16', 'type': 'dictionary', 'children': []}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'feedin_case_lower'"}; {'id': '22', 'type': 'float', 'children': [], 'value': '0.9'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'load_case_upper'"}; {'id': '28', 'type': 'float', 'children': [], 'value': '1.1'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '32', 'type': 'subscript', 'children': ['33', '38']}, {'id': '33', 'type': 'subscript', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'hv_mv_trafo_offset'"}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'control_deviation'}; {'id': '42', 'type': 'subscript', 'children': ['43', '48']}, {'id': '43', 'type': 'subscript', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}; {'id': '48', 'type': 'string', 'children': [], 'value': "'hv_mv_trafo_control_deviation'"}, {'id': '49', 'type': 'if_statement', 'children': ['50', '53', '92', '135']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '=='}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'voltage_levels'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'mv_lv'"}, {'id': '53', 'type': 'block', 'children': ['54', '73']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59', '60']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'feedin_case_upper'"}, {'id': '59', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '66'], 'value': '+'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '+'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'control_deviation'}; {'id': '66', 'type': 'subscript', 'children': ['67', '72']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'mv_lv_feedin_case_max_v_deviation'"}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78', '79']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'load_case_lower'"}; {'id': '78', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '85'], 'value': '-'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '-'}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'control_deviation'}, {'id': '85', 'type': 'subscript', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}, {'id': '91', 'type': 'string', 'children': [], 'value': "'mv_lv_load_case_max_v_deviation'"}; {'id': '92', 'type': 'elif_clause', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'voltage_levels'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'mv'"}; {'id': '96', 'type': 'block', 'children': ['97', '116']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102', '103']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'feedin_case_upper'"}; {'id': '102', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '109'], 'value': '+'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '108'], 'value': '+'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'control_deviation'}, {'id': '109', 'type': 'subscript', 'children': ['110', '115']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}, {'id': '115', 'type': 'string', 'children': [], 'value': "'mv_feedin_case_max_v_deviation'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121', '122']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'load_case_lower'"}, {'id': '121', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '128'], 'value': '-'}, {'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '-'}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'control_deviation'}; {'id': '128', 'type': 'subscript', 'children': ['129', '134']}, {'id': '129', 'type': 'subscript', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'grid_expansion_allowed_voltage_deviations'"}; {'id': '134', 'type': 'string', 'children': [], 'value': "'mv_load_case_max_v_deviation'"}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'Specified mode {} is not a valid option.'"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'voltage_levels'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_upper'}; {'id': '150', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '151', 'type': 'call', 'children': ['152', '161']}; {'id': '152', 'type': 'attribute', 'children': ['153', '160']}, {'id': '153', 'type': 'attribute', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'timeseries'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'timesteps_load_feedin_case'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'apply'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'lambda', 'children': ['163', '165']}, {'id': '163', 'type': 'lambda_parameters', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'{}_upper'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176', '177']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_lower'}; {'id': '176', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '177', 'type': 'call', 'children': ['178', '187']}; {'id': '178', 'type': 'attribute', 'children': ['179', '186']}, {'id': '179', 'type': 'attribute', 'children': ['180', '185']}; {'id': '180', 'type': 'attribute', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'timeseries'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'timesteps_load_feedin_case'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'apply'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'lambda', 'children': ['189', '191']}, {'id': '189', 'type': 'lambda_parameters', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_per_case'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'string', 'children': [], 'value': "'{}_lower'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '202', 'type': 'call', 'children': ['203', '210']}, {'id': '203', 'type': 'attribute', 'children': ['204', '209']}; {'id': '204', 'type': 'attribute', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'mv_grid'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '210', 'type': 'argument_list', 'children': []}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'crit_nodes_grid'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': '_voltage_deviation'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '219', '220', '221']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_upper'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'v_dev_allowed_lower'}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'voltage_level'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'mv'"}; {'id': '224', 'type': 'if_statement', 'children': ['225', '229', '269']}, {'id': '225', 'type': 'not_operator', 'children': ['226']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'crit_nodes_grid'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '229', 'type': 'block', 'children': ['230', '249']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '237']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'mv_grid'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'crit_nodes_grid'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'sort_values'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '246']}; {'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '244', 'type': 'list', 'children': ['245'], 'value': "['v_mag_pu']"}, {'id': '245', 'type': 'string', 'children': [], 'value': "'v_mag_pu'"}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '248', 'type': 'False', 'children': []}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'string', 'children': [], 'value': "'==> {} node(s) in MV grid has/have voltage issues.'"}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'subscript', 'children': ['261', '268']}, {'id': '261', 'type': 'attribute', 'children': ['262', '267']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'mv_grid'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '268', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '269', 'type': 'else_clause', 'children': ['270']}; {'id': '270', 'type': 'block', 'children': ['271']}, {'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': 'debug'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'string', 'children': [], 'value': "'==> No voltage issues in MV grid.'"}; {'id': '278', 'type': 'return_statement', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'crit_nodes'}
def mv_voltage_deviation(network, voltage_levels='mv_lv'): crit_nodes = {} v_dev_allowed_per_case = {} v_dev_allowed_per_case['feedin_case_lower'] = 0.9 v_dev_allowed_per_case['load_case_upper'] = 1.1 offset = network.config[ 'grid_expansion_allowed_voltage_deviations']['hv_mv_trafo_offset'] control_deviation = network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'hv_mv_trafo_control_deviation'] if voltage_levels == 'mv_lv': v_dev_allowed_per_case['feedin_case_upper'] = \ 1 + offset + control_deviation + network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_lv_feedin_case_max_v_deviation'] v_dev_allowed_per_case['load_case_lower'] = \ 1 + offset - control_deviation - network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_lv_load_case_max_v_deviation'] elif voltage_levels == 'mv': v_dev_allowed_per_case['feedin_case_upper'] = \ 1 + offset + control_deviation + network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_feedin_case_max_v_deviation'] v_dev_allowed_per_case['load_case_lower'] = \ 1 + offset - control_deviation - network.config[ 'grid_expansion_allowed_voltage_deviations'][ 'mv_load_case_max_v_deviation'] else: raise ValueError( 'Specified mode {} is not a valid option.'.format(voltage_levels)) v_dev_allowed_upper = \ network.timeseries.timesteps_load_feedin_case.case.apply( lambda _: v_dev_allowed_per_case['{}_upper'.format(_)]) v_dev_allowed_lower = \ network.timeseries.timesteps_load_feedin_case.case.apply( lambda _: v_dev_allowed_per_case['{}_lower'.format(_)]) nodes = network.mv_grid.graph.nodes() crit_nodes_grid = _voltage_deviation( network, nodes, v_dev_allowed_upper, v_dev_allowed_lower, voltage_level='mv') if not crit_nodes_grid.empty: crit_nodes[network.mv_grid] = crit_nodes_grid.sort_values( by=['v_mag_pu'], ascending=False) logger.debug( '==> {} node(s) in MV grid has/have voltage issues.'.format( crit_nodes[network.mv_grid].shape[0])) else: logger.debug('==> No voltage issues in MV grid.') return crit_nodes
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'calc_geo_lines_in_buffer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'network'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'grid'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'radius_inc'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '99']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'while_statement', 'children': ['15', '17']}, {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'lines'}, {'id': '17', 'type': 'block', 'children': ['18', '31', '40', '95']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'node_shp'}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'transform'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '28']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'proj2equidistant'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'buffer_zone_shp'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'node_shp'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '49']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'line'}; {'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': 'grid'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'block', 'children': ['50', '56', '80']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'adj_nodes'"}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'branch_shp'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'transform'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '66']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'proj2equidistant'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'network'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'LineString'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'list', 'children': ['70', '75'], 'value': '[nodes[0].geom, nodes[1].geom]'}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'geom'}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'geom'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '87']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'buffer_zone_shp'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'intersects'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'branch_shp'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'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': 'lines'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'radius'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'radius_inc'}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '106', 'type': 'lambda', 'children': ['107', '109']}, {'id': '107', 'type': 'lambda_parameters', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}
def calc_geo_lines_in_buffer(network, node, grid, radius, radius_inc): lines = [] while not lines: node_shp = transform(proj2equidistant(network), node.geom) buffer_zone_shp = node_shp.buffer(radius) for line in grid.graph.lines(): nodes = line['adj_nodes'] branch_shp = transform(proj2equidistant(network), LineString([nodes[0].geom, nodes[1].geom])) if buffer_zone_shp.intersects(branch_shp): lines.append(line) radius += radius_inc return sorted(lines, key=lambda _: repr(_))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_group_by_size_greedy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj_list'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tot_groups'}; {'id': '6', 'type': 'block', 'children': ['7', '25', '36', '63']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14', '22']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'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': 'x'}, {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'size'"}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '24', 'type': 'True', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '28', 'type': 'list_comprehension', 'children': ['29', '30']}, {'id': '29', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tot_groups'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '40', '44']}, {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '44', 'type': 'block', 'children': ['45', '56']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'current_group'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '%'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'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': 'current_group'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '63', 'type': 'return_statement', 'children': ['64']}
def _group_by_size_greedy(obj_list, tot_groups): sorted_list = sorted(obj_list, key=lambda x: x['size'], reverse=True) groups = [[] for _ in range(tot_groups)] for index, obj in enumerate(sorted_list): current_group = groups[index % len(groups)] current_group.append(obj) return groups
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dimensions_from_subgroups'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '5', 'type': 'block', 'children': ['6', '10']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'letters'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'XYABCDEFGHIJKLMNOPQRSTUVWZ'"}; {'id': '10', 'type': 'return_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'list_comprehension', 'children': ['17', '26']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "'dim{0}={1}'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sg'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']}, {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dim'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sg'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'letters'}
def dimensions_from_subgroups(s): letters = 'XYABCDEFGHIJKLMNOPQRSTUVWZ' return ' '.join(['dim{0}={1}'.format(dim, sg.name) for dim, sg in zip(letters, s)])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_composite_from_subgroups'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '36']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'dims'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '23']}, {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'letter'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sg'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'ABCDEFGHIJKLMNOPQRSTUVWZ'"}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '20', 'type': 'slice', 'children': ['21', '22']}, {'id': '21', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '22', 'type': 'colon', 'children': []}, {'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': 'dims'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'append'}, {'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': "'dim{0}'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'letter'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dims'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'dims'}
def filter_composite_from_subgroups(s): dims = [] for letter, sg in zip('ABCDEFGHIJKLMNOPQRSTUVWZ', s[2:]): dims.append('dim{0}'.format(letter)) if dims: return ' '.join(dims)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_videos_for_filter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'video_filter'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SortDirection'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '29', '33', '63', '116']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'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': 'Video'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'dictionary_splat', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'video_filter'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'paginator_context'}; {'id': '32', 'type': 'dictionary', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '35', 'type': 'block', 'children': ['36', '48']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'videos'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'order_by'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort_field'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'string', 'children': [], 'value': '"edx_video_id"'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '54']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'SortDirection'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'videos'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}, {'id': '65', 'type': 'block', 'children': ['66', '75', '83', '97']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'videos_per_page'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'videos_per_page'"}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'paginator'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'Paginator'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'videos_per_page'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'paginator'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'page_number'"}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'paginator_context'}; {'id': '100', 'type': 'dictionary', 'children': ['101', '106', '113']}, {'id': '101', 'type': 'pair', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'current_page'"}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'videos'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'number'}; {'id': '106', 'type': 'pair', 'children': ['107', '108']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'total_pages'"}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'videos'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'paginator'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'num_pages'}, {'id': '113', 'type': 'pair', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'items_on_one_page'"}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'videos_per_page'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'expression_list', 'children': ['118', '128']}; {'id': '118', 'type': 'generator_expression', 'children': ['119', '125']}, {'id': '119', 'type': 'attribute', 'children': ['120', '124']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'VideoSerializer'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'video'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'video'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'videos'}
def _get_videos_for_filter(video_filter, sort_field=None, sort_dir=SortDirection.asc, pagination_conf=None): videos = Video.objects.filter(**video_filter) paginator_context = {} if sort_field: videos = videos.order_by(sort_field.value, "edx_video_id") if sort_dir == SortDirection.desc: videos = videos.reverse() if pagination_conf: videos_per_page = pagination_conf.get('videos_per_page') paginator = Paginator(videos, videos_per_page) videos = paginator.page(pagination_conf.get('page_number')) paginator_context = { 'current_page': videos.number, 'total_pages': videos.paginator.num_pages, 'items_on_one_page':videos_per_page } return (VideoSerializer(video).data for video in videos), paginator_context
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_videos_for_course'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'course_id'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SortDirection'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_get_videos_for_filter'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '33', '34', '35']}, {'id': '21', 'type': 'dictionary', 'children': ['22', '30']}; {'id': '22', 'type': 'pair', 'children': ['23', '24']}, {'id': '23', 'type': 'string', 'children': [], 'value': "'courses__course_id'"}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'text_type'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'course_id'}; {'id': '30', 'type': 'pair', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "'courses__is_hidden'"}; {'id': '32', 'type': 'False', 'children': []}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_field'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pagination_conf'}
def get_videos_for_course(course_id, sort_field=None, sort_dir=SortDirection.asc, pagination_conf=None): return _get_videos_for_filter( {'courses__course_id': six.text_type(course_id), 'courses__is_hidden': False}, sort_field, sort_dir, pagination_conf, )
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_videos_for_ids'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'edx_video_ids'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SortDirection'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'asc'}, {'id': '13', 'type': 'block', 'children': ['14', '28']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '19']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'videos'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '__'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_get_videos_for_filter'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '26', '27']}; {'id': '22', 'type': 'dictionary', 'children': ['23']}, {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"edx_video_id__in"'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'edx_video_ids'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sort_field'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_dir'}; {'id': '28', 'type': 'return_statement', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'videos'}
def get_videos_for_ids( edx_video_ids, sort_field=None, sort_dir=SortDirection.asc ): videos, __ = _get_videos_for_filter( {"edx_video_id__in":edx_video_ids}, sort_field, sort_dir, ) return videos
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'put'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pb_type'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'offline'"}; {'id': '10', 'type': 'block', 'children': ['11', '23']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '17']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'not'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pb_type'}; {'id': '14', 'type': 'tuple', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'offline'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'realtime'"}, {'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': 'string', 'children': [], 'value': "'Invalid PB type.'"}, {'id': '23', 'type': 'with_statement', 'children': ['24', '29']}; {'id': '24', 'type': 'with_clause', 'children': ['25']}, {'id': '25', 'type': 'with_item', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_mutex'}, {'id': '29', 'type': 'block', 'children': ['30', '44', '59', '65', '89', '97', '105', '114', '122']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'added_time'}, {'id': '33', 'type': 'call', 'children': ['34', '43']}; {'id': '34', 'type': 'attribute', 'children': ['35', '42']}, {'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': 'datetime'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'utcnow'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'isoformat'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '47', 'type': 'tuple', 'children': ['48', '49', '56', '57', '58']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'priority'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '-'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'maxsize'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'block_id'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pb_type'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'added_time'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'augmented_assignment', 'children': ['61', '64'], 'value': '+='}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_index'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '76']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '75'], 'value': 'is'}, {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'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': '_block_map'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'block_id'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'raise_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}, {'id': '83', 'type': 'concatenated_string', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '\'ERROR: Block id "{}" already exists in \''}, {'id': '85', 'type': 'string', 'children': [], 'value': "'PC PB queue!'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'block_id'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '96']}, {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_block_map'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'block_id'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'LOG'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'string', 'children': [], 'value': '"Adding PB %s to queue"'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'block_id'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '112']}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_queue'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_queue'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': '_queue'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '129', 'type': 'argument_list', 'children': []}
def put(self, block_id, priority, pb_type='offline'): if pb_type not in ('offline', 'realtime'): raise ValueError('Invalid PB type.') with self._mutex: added_time = datetime.datetime.utcnow().isoformat() entry = (priority, sys.maxsize-self._index, block_id, pb_type, added_time) self._index += 1 if self._block_map.get(block_id) is not None: raise KeyError('ERROR: Block id "{}" already exists in ' 'PC PB queue!'. format(block_id)) self._block_map[block_id] = entry LOG.debug("Adding PB %s to queue", block_id) self._queue.append(entry) self._queue.sort() self._queue.reverse()
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_device'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '18', '22', '107', '114']}; {'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': 'devices'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'dev'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30', '79']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dev'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'all_models'}; {'id': '30', 'type': 'block', 'children': ['31', '47']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'all_dev'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '46']}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_models'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dev'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'all_dev'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '57']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'devices'}, {'id': '57', 'type': 'block', 'children': ['58', '72']}; {'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': 'idx'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '63', 'type': 'argument_list', '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': 'devices'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'item'}; {'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': 'names'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '79', 'type': 'elif_clause', 'children': ['80', '85']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'in'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'dev'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'devices'}, {'id': '85', 'type': 'block', 'children': ['86', '100']}; {'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': 'idx'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'devices'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'dev'}; {'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': 'names'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'dev'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '114', 'type': 'for_statement', 'children': ['115', '118', '123']}, {'id': '115', 'type': 'pattern_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '131']}; {'id': '126', 'type': 'subscript', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'name'}
def sort_device(self): self.devices.sort() idx = [] names = [] for dev in order: if dev in all_models: all_dev = list(sorted(all_models[dev].keys())) for item in all_dev: if item in self.devices: idx.append(self.devices.index(item)) names.append(item) elif dev in self.devices: idx.append(self.devices.index(dev)) names.append(dev) idx = sorted(idx) for id, name in zip(idx, names): self.devices[id] = name
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export_csv'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'formatted'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_idx'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'%.18e'"}, {'id': '21', 'type': 'block', 'children': ['22', '32', '48', '59', '68']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '25']}, {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'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': 'idx'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_idx'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '35']}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_header'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'formatted'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'formatted'}; {'id': '48', 'type': 'assert_statement', 'children': ['49', '58']}, {'id': '49', 'type': 'comparison_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': 'idx'}; {'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': 'header'}; {'id': '58', 'type': 'string', 'children': [], 'value': '"Idx length does not match header length"'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'body'}; {'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': 'get_values'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '68', 'type': 'with_statement', 'children': ['69', '79']}, {'id': '69', 'type': 'with_clause', 'children': ['70']}; {'id': '70', 'type': 'with_item', 'children': ['71']}, {'id': '71', 'type': 'as_pattern', 'children': ['72', '77']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '77', 'type': 'as_pattern_target', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '79', 'type': 'block', 'children': ['80', '94']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'fd'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '93'], 'value': '+'}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "','"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'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': 'np'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'savetxt'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102', '105']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'fd'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'delimiter'}, {'id': '107', 'type': 'string', 'children': [], 'value': "','"}
def export_csv(self, path, idx=None, header=None, formatted=False, sort_idx=True, fmt='%.18e'): if not idx: idx = self._idx if not header: header = self.get_header(idx, formatted=formatted) assert len(idx) == len(header), \ "Idx length does not match header length" body = self.get_values(idx) with open(path, 'w') as fd: fd.write(','.join(header) + '\n') np.savetxt(fd, body, fmt=fmt, delimiter=',')
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_event_times'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '23', '48', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '15', 'type': 'argument_list', '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': 'Breaker'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_times'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '32']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '25', 'type': 'attribute', 'children': ['26', '31']}; {'id': '26', 'type': 'subscript', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '__dict__'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Event'"}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'all_models'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '47']}; {'id': '40', 'type': 'attribute', 'children': ['41', '46']}, {'id': '41', 'type': 'subscript', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_times'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '64', 'type': 'return_statement', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'times'}
def get_event_times(self): times = [] times.extend(self.Breaker.get_times()) for model in self.__dict__['Event'].all_models: times.extend(self.__dict__[model].get_times()) if times: times = sorted(list(set(times))) return times
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sort_field'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '34', '43', '57']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_direction'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"dir"'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'field_name'}; {'id': '20', 'type': 'conditional_expression', 'children': ['21', '32', '33'], 'value': 'if'}, {'id': '21', 'type': 'parenthesized_expression', 'children': ['22']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '31'], 'value': 'or'}, {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'GET'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"sort"'}, {'id': '31', 'type': 'string', 'children': [], 'value': '""'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort_direction'}, {'id': '33', 'type': 'string', 'children': [], 'value': '""'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_sign'}, {'id': '37', 'type': 'conditional_expression', 'children': ['38', '39', '42'], 'value': 'if'}; {'id': '38', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_direction'}, {'id': '41', 'type': 'string', 'children': [], 'value': '"desc"'}; {'id': '42', 'type': 'string', 'children': [], 'value': '""'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'result_field'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"{sign}{field}"'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54']}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sign'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort_sign'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'field_name'}, {'id': '57', 'type': 'return_statement', 'children': ['58']}
def get_sort_field(request): sort_direction = request.GET.get("dir") field_name = (request.GET.get("sort") or "") if sort_direction else "" sort_sign = "-" if sort_direction == "desc" else "" result_field = "{sign}{field}".format(sign=sort_sign, field=field_name) return result_field
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'linkage_group_ordering'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'linkage_records'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '77']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'new_records'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '11', 'type': 'argument_list', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '16', '28']}, {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'lg_name'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'linkage_group'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'linkage_records'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'block', 'children': ['29', '35']}, {'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': 'new_records'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'lg_name'}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'linkage_group'}; {'id': '38', 'type': 'block', 'children': ['39', '46', '52', '58', '68']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'init_contig'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '-'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'record'}, {'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': 'end'}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'record'}, {'id': '57', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'new_record'}, {'id': '61', 'type': 'list', 'children': ['62', '63', '65', '66', '67'], 'value': '[init_contig, -3, start, end, 1]'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'init_contig'}, {'id': '63', 'type': 'unary_operator', 'children': ['64'], 'value': '-'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'new_records'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'lg_name'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'new_record'}, {'id': '77', 'type': 'return_statement', 'children': ['78']}
def linkage_group_ordering(linkage_records): new_records = dict() for lg_name, linkage_group in itertools.groupby( linkage_records, operator.itemgetter(0) ): new_records[lg_name] = [] for record in linkage_group: init_contig = record[-1] start = record[1] end = record[2] new_record = [init_contig, -3, start, end, 1] new_records[lg_name].append(new_record) return new_records
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '43']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_issues'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37', '40']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'github'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'milestone'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'open'"}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'assignee'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'mentioned'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'created'"}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'min'"}; {'id': '40', 'type': 'default_parameter', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'block', 'children': ['44', '46', '54', '67', '79', '83', '92', '101', '110', '119', '128', '137', '146', '159', '172', '185', '189', '205', '249']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "'''\n Returns information for all issues in a given repository, based on the search options.\n .. versionadded:: 2016.11.0\n repo_name\n The name of the repository for which to list issues. This argument is\n required, either passed via the CLI, or defined in the configured\n profile. A ``repo_name`` passed as a CLI argument will override the\n repo_name defined in the configured profile, if provided.\n profile\n The name of the profile configuration to use. Defaults to ``github``.\n milestone\n The number of a GitHub milestone, or a string of either ``*`` or\n ``none``.\n If a number is passed, it should refer to a milestone by its number\n field. Use the ``github.get_milestone`` function to obtain a milestone's\n number.\n If the string ``*`` is passed, issues with any milestone are\n accepted. If the string ``none`` is passed, issues without milestones\n are returned.\n state\n Indicates the state of the issues to return. Can be either ``open``,\n ``closed``, or ``all``. Default is ``open``.\n assignee\n Can be the name of a user. Pass in ``none`` (as a string) for issues\n with no assigned user or ``*`` for issues assigned to any user.\n creator\n The user that created the issue.\n mentioned\n A user that's mentioned in the issue.\n labels\n A string of comma separated label names. For example, ``bug,ui,@high``.\n sort\n What to sort results by. Can be either ``created``, ``updated``, or\n ``comments``. Default is ``created``.\n direction\n The direction of the sort. Can be either ``asc`` or ``desc``. Default\n is ``desc``.\n since\n Only issues updated at or after this time are returned. This is a\n timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``.\n output\n The amount of data returned by each issue. Defaults to ``min``. Change\n to ``full`` to see all issue output.\n per_page\n GitHub paginates data in their API calls. Use this value to increase or\n decrease the number of issues gathered from GitHub, per page. If not set,\n GitHub defaults are used. Maximum is 100.\n CLI Example:\n .. code-block:: bash\n salt myminion github.get_issues my-github-repo\n '''"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'org_name'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'org_name'"}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '57', 'type': 'None', 'children': []}; {'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': 'repo_name'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'repo_name'"}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'list', 'children': ['76', '77', '78'], 'value': "['repos', org_name, repo_name]"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'repos'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'org_name'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '82', 'type': 'dictionary', 'children': []}, {'id': '83', 'type': 'if_statement', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'milestone'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'milestone'"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'milestone'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'assignee'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'assignee'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'assignee'}, {'id': '101', 'type': 'if_statement', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'creator'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'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': 'args'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'creator'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'creator'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'mentioned'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'mentioned'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'mentioned'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'labels'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'labels'"}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'since'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'since'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'since'}, {'id': '137', 'type': 'if_statement', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'per_page'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'per_page'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '152']}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '149'], 'value': 'and'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '!='}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '151', 'type': 'string', 'children': [], 'value': "'open'"}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '158']}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '157', 'type': 'string', 'children': [], 'value': "'state'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '165']}; {'id': '160', 'type': 'boolean_operator', 'children': ['161', '162'], 'value': 'and'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '!='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'created'"}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '171']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '178']}, {'id': '173', 'type': 'boolean_operator', 'children': ['174', '175'], 'value': 'and'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '!='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '183', 'type': 'string', 'children': [], 'value': "'direction'"}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '188', 'type': 'dictionary', 'children': []}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'issues'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': '_query'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196', '199', '202']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'issues'"}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'issue'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'issues'}; {'id': '208', 'type': 'block', 'children': ['209', '218', '227']}, {'id': '209', 'type': 'if_statement', 'children': ['210', '216']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'issue'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'string', 'children': [], 'value': "'pull_request'"}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'continue_statement', 'children': []}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'issue_id'}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'issue'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '227', 'type': 'if_statement', 'children': ['228', '231', '238']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': '=='}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'full'"}, {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}, {'id': '233', 'type': 'assignment', 'children': ['234', '237']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'issue_id'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'issue'}; {'id': '238', 'type': 'else_clause', 'children': ['239']}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '245']}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'issue_id'}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': '_format_issue'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'issue'}, {'id': '249', 'type': 'return_statement', 'children': ['250']}
def get_issues(repo_name=None, profile='github', milestone=None, state='open', assignee=None, creator=None, mentioned=None, labels=None, sort='created', direction='desc', since=None, output='min', per_page=None): ''' Returns information for all issues in a given repository, based on the search options. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. milestone The number of a GitHub milestone, or a string of either ``*`` or ``none``. If a number is passed, it should refer to a milestone by its number field. Use the ``github.get_milestone`` function to obtain a milestone's number. If the string ``*`` is passed, issues with any milestone are accepted. If the string ``none`` is passed, issues without milestones are returned. state Indicates the state of the issues to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. assignee Can be the name of a user. Pass in ``none`` (as a string) for issues with no assigned user or ``*`` for issues assigned to any user. creator The user that created the issue. mentioned A user that's mentioned in the issue. labels A string of comma separated label names. For example, ``bug,ui,@high``. sort What to sort results by. Can be either ``created``, ``updated``, or ``comments``. Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. since Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_issues my-github-repo ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if milestone: args['milestone'] = milestone if assignee: args['assignee'] = assignee if creator: args['creator'] = creator if mentioned: args['mentioned'] = mentioned if labels: args['labels'] = labels if since: args['since'] = since if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'created': args['sort'] = sort if direction and direction != 'desc': args['direction'] = direction ret = {} issues = _query(profile, action=action, command='issues', args=args) for issue in issues: if issue.get('pull_request'): continue issue_id = issue.get('id') if output == 'full': ret[issue_id] = issue else: ret[issue_id] = _format_issue(issue) return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_milestones'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'github'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'open'"}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'due_on'"}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'asc'"}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'min'"}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26', '28', '36', '49', '61', '65', '74', '87', '100', '113', '117', '133', '186']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'''\n Return information about milestones for a given repository.\n .. versionadded:: 2016.11.0\n repo_name\n The name of the repository for which to list issues. This argument is\n required, either passed via the CLI, or defined in the configured\n profile. A ``repo_name`` passed as a CLI argument will override the\n repo_name defined in the configured profile, if provided.\n profile\n The name of the profile configuration to use. Defaults to ``github``.\n state\n The state of the milestone. Either ``open``, ``closed``, or ``all``.\n Default is ``open``.\n sort\n What to sort results by. Either ``due_on`` or ``completeness``. Default\n is ``due_on``.\n direction\n The direction of the sort. Either ``asc`` or ``desc``. Default is ``asc``.\n output\n The amount of data returned by each issue. Defaults to ``min``. Change\n to ``full`` to see all issue output.\n per_page\n GitHub paginates data in their API calls. Use this value to increase or\n decrease the number of issues gathered from GitHub, per page. If not set,\n GitHub defaults are used.\n CLI Example:\n .. code-block:: bash\n salt myminion github.get_milestones\n '''"}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'org_name'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'org_name'"}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'repo_name'"}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'list', 'children': ['58', '59', '60'], 'value': "['repos', org_name, repo_name]"}; {'id': '58', 'type': 'string', 'children': [], 'value': "'repos'"}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'org_name'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '64', 'type': 'dictionary', 'children': []}, {'id': '65', 'type': 'if_statement', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'per_page'}, {'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': 'args'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'per_page'"}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '80']}, {'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'and'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': '!='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'open'"}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'state'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '93']}; {'id': '88', 'type': 'boolean_operator', 'children': ['89', '90'], 'value': 'and'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '!='}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'due_on'"}, {'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': 'args'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '106']}, {'id': '101', 'type': 'boolean_operator', 'children': ['102', '103'], 'value': 'and'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '!='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'asc'"}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'direction'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '116', 'type': 'dictionary', 'children': []}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'milestones'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '_query'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '127', '130']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'milestones'"}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'milestone'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'milestones'}; {'id': '136', 'type': 'block', 'children': ['137', '146']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'milestone_id'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'milestone'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150', '157']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '=='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'full'"}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'milestone_id'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'milestone'}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159', '166', '173', '180']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'milestone'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': "'creator'"}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'milestone'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'html_url'"}, {'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': 'milestone'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'labels_url'"}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '185']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'milestone_id'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'milestone'}; {'id': '186', 'type': 'return_statement', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ret'}
def get_milestones(repo_name=None, profile='github', state='open', sort='due_on', direction='asc', output='min', per_page=None): ''' Return information about milestones for a given repository. .. versionadded:: 2016.11.0 repo_name The name of the repository for which to list issues. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the repo_name defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state The state of the milestone. Either ``open``, ``closed``, or ``all``. Default is ``open``. sort What to sort results by. Either ``due_on`` or ``completeness``. Default is ``due_on``. direction The direction of the sort. Either ``asc`` or ``desc``. Default is ``asc``. output The amount of data returned by each issue. Defaults to ``min``. Change to ``full`` to see all issue output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of issues gathered from GitHub, per page. If not set, GitHub defaults are used. CLI Example: .. code-block:: bash salt myminion github.get_milestones ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'due_on': args['sort'] = sort if direction and direction != 'asc': args['direction'] = direction ret = {} milestones = _query(profile, action=action, command='milestones', args=args) for milestone in milestones: milestone_id = milestone.get('id') if output == 'full': ret[milestone_id] = milestone else: milestone.pop('creator') milestone.pop('html_url') milestone.pop('labels_url') ret[milestone_id] = milestone return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '31']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_prs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'github'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'open'"}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'created'"}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'desc'"}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'min'"}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32', '34', '42', '55', '67', '71', '80', '89', '98', '111', '124', '137', '141', '157', '192']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'string', 'children': [], 'value': "'''\n Returns information for all pull requests in a given repository, based on\n the search options provided.\n .. versionadded:: 2017.7.0\n repo_name\n The name of the repository for which to list pull requests. This\n argument is required, either passed via the CLI, or defined in the\n configured profile. A ``repo_name`` passed as a CLI argument will\n override the ``repo_name`` defined in the configured profile, if\n provided.\n profile\n The name of the profile configuration to use. Defaults to ``github``.\n state\n Indicates the state of the pull requests to return. Can be either\n ``open``, ``closed``, or ``all``. Default is ``open``.\n head\n Filter pull requests by head user and branch name in the format of\n ``user:ref-name``. Example: ``'github:new-script-format'``. Default\n is ``None``.\n base\n Filter pulls by base branch name. Example: ``gh-pages``. Default is\n ``None``.\n sort\n What to sort results by. Can be either ``created``, ``updated``,\n ``popularity`` (comment count), or ``long-running`` (age, filtering\n by pull requests updated within the last month). Default is ``created``.\n direction\n The direction of the sort. Can be either ``asc`` or ``desc``. Default\n is ``desc``.\n output\n The amount of data returned by each pull request. Defaults to ``min``.\n Change to ``full`` to see all pull request output.\n per_page\n GitHub paginates data in their API calls. Use this value to increase or\n decrease the number of pull requests gathered from GitHub, per page. If\n not set, GitHub defaults are used. Maximum is 100.\n CLI Example:\n .. code-block:: bash\n salt myminion github.get_prs\n salt myminion github.get_prs base=2016.11\n '''"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'org_name'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'profile'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'org_name'"}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'repo_name'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_get_config_value'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'repo_name'"}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'list', 'children': ['64', '65', '66'], 'value': "['repos', org_name, repo_name]"}; {'id': '64', 'type': 'string', 'children': [], 'value': "'repos'"}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'org_name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'repo_name'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '70', 'type': 'dictionary', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'head'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'head'"}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'head'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'base'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'per_page'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'per_page'"}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'per_page'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '104']}, {'id': '99', 'type': 'boolean_operator', 'children': ['100', '101'], 'value': 'and'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '!='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'open'"}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '110']}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '109', 'type': 'string', 'children': [], 'value': "'state'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '117']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '114'], 'value': 'and'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '!='}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'created'"}, {'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': 'args'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'sort'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '130']}, {'id': '125', 'type': 'boolean_operator', 'children': ['126', '127'], 'value': 'and'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '!='}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'desc'"}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}, {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'direction'"}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'direction'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '140', 'type': 'dictionary', 'children': []}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'prs'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': '_query'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '151', '154']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'pulls'"}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'pr_'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'prs'}; {'id': '160', 'type': 'block', 'children': ['161', '170']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'pr_id'}; {'id': '164', 'type': 'call', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pr_'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174', '181']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '=='}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '173', 'type': 'string', 'children': [], 'value': "'full'"}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '180']}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'pr_id'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'pr_'}, {'id': '181', 'type': 'else_clause', 'children': ['182']}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pr_id'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': '_format_pr'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'pr_'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'ret'}
def get_prs(repo_name=None, profile='github', state='open', head=None, base=None, sort='created', direction='desc', output='min', per_page=None): ''' Returns information for all pull requests in a given repository, based on the search options provided. .. versionadded:: 2017.7.0 repo_name The name of the repository for which to list pull requests. This argument is required, either passed via the CLI, or defined in the configured profile. A ``repo_name`` passed as a CLI argument will override the ``repo_name`` defined in the configured profile, if provided. profile The name of the profile configuration to use. Defaults to ``github``. state Indicates the state of the pull requests to return. Can be either ``open``, ``closed``, or ``all``. Default is ``open``. head Filter pull requests by head user and branch name in the format of ``user:ref-name``. Example: ``'github:new-script-format'``. Default is ``None``. base Filter pulls by base branch name. Example: ``gh-pages``. Default is ``None``. sort What to sort results by. Can be either ``created``, ``updated``, ``popularity`` (comment count), or ``long-running`` (age, filtering by pull requests updated within the last month). Default is ``created``. direction The direction of the sort. Can be either ``asc`` or ``desc``. Default is ``desc``. output The amount of data returned by each pull request. Defaults to ``min``. Change to ``full`` to see all pull request output. per_page GitHub paginates data in their API calls. Use this value to increase or decrease the number of pull requests gathered from GitHub, per page. If not set, GitHub defaults are used. Maximum is 100. CLI Example: .. code-block:: bash salt myminion github.get_prs salt myminion github.get_prs base=2016.11 ''' org_name = _get_config_value(profile, 'org_name') if repo_name is None: repo_name = _get_config_value(profile, 'repo_name') action = '/'.join(['repos', org_name, repo_name]) args = {} if head: args['head'] = head if base: args['base'] = base if per_page: args['per_page'] = per_page if state and state != 'open': args['state'] = state if sort and sort != 'created': args['sort'] = sort if direction and direction != 'desc': args['direction'] = direction ret = {} prs = _query(profile, action=action, command='pulls', args=args) for pr_ in prs: pr_id = pr_.get('id') if output == 'full': ret[pr_id] = pr_ else: ret[pr_id] = _format_pr(pr_) return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_diff_lists'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'old'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'comparator'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '48', '64', '73', '151', '157']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''\n Compare lists to extract the changes\n :param old: old list\n :param new: new list\n :return: a dictionary with ``unchanged``, ``new``, ``deleted`` and ``sorted`` keys\n The sorted list is the union of unchanged and new lists, but keeping the original\n order from the new list.\n '''"}; {'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']}, {'id': '11', 'type': 'function_name', 'children': [], 'value': '_remove_indent'}; {'id': '12', 'type': 'parameters', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '14', 'type': 'block', 'children': ['15', '17', '26', '32', '46']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'''\n Remove the XML indentation to compare XML trees more easily\n '''"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'node_copy'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'node_copy'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '39']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'node_copy'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'tail'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'node_copy'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '51', 'type': 'dictionary', 'children': ['52', '55', '58', '61']}; {'id': '52', 'type': 'pair', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': "'unchanged'"}; {'id': '54', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '55', 'type': 'pair', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'new'"}, {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'pair', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'deleted'"}; {'id': '60', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'sorted'"}, {'id': '63', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'old_devices'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'old'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'new_item'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '76', 'type': 'block', 'children': ['77', '97']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '80', 'type': 'list_comprehension', 'children': ['81', '82', '85']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '82', 'type': 'for_in_clause', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'old_devices'}, {'id': '85', 'type': 'if_clause', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'comparator'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '93']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_remove_indent'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_remove_indent'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'new_item'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99', '131']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '99', 'type': 'block', 'children': ['100', '109', '120']}; {'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': 'old_devices'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '116']}, {'id': '111', 'type': 'attribute', 'children': ['112', '115']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'unchanged'"}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '127']}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'sorted'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133', '142']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '140']}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'new'"}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'new_item'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'sorted'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'new_item'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'deleted'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'old_devices'}, {'id': '157', 'type': 'return_statement', 'children': ['158']}
def _diff_lists(old, new, comparator): ''' Compare lists to extract the changes :param old: old list :param new: new list :return: a dictionary with ``unchanged``, ``new``, ``deleted`` and ``sorted`` keys The sorted list is the union of unchanged and new lists, but keeping the original order from the new list. ''' def _remove_indent(node): ''' Remove the XML indentation to compare XML trees more easily ''' node_copy = copy.deepcopy(node) node_copy.text = None for item in node_copy.iter(): item.tail = None return node_copy diff = {'unchanged': [], 'new': [], 'deleted': [], 'sorted': []} old_devices = copy.deepcopy(old) for new_item in new: found = [item for item in old_devices if comparator(_remove_indent(item), _remove_indent(new_item))] if found: old_devices.remove(found[0]) diff['unchanged'].append(found[0]) diff['sorted'].append(found[0]) else: diff['new'].append(new_item) diff['sorted'].append(new_item) diff['deleted'] = old_devices return diff
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_job_sorting_key'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20', '31']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'is'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_base_graph'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}, {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'MAX_JOBS'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '1000000'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '28']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'not'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'addr'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_node_addr_visiting_order'}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'MAX_JOBS'}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_node_addr_visiting_order'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'job'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'addr'}
def _job_sorting_key(self, job): if self._base_graph is None: return 0 MAX_JOBS = 1000000 if job.addr not in self._node_addr_visiting_order: return MAX_JOBS return self._node_addr_visiting_order.index(job.addr)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'instruction_addresses'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '38']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'addrs'}, {'id': '9', 'type': 'list', 'children': [], 'value': '[ ]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '26']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'blocks'}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'lambda', 'children': ['21', '23']}, {'id': '21', 'type': 'lambda_parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'addrs'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'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': 'b'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'instruction_addresses'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '46']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'addrs'}; {'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': 'x'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}
def instruction_addresses(self): addrs = [ ] for b in sorted(self.blocks, key=lambda x: x.addr): addrs.extend(b.instruction_addresses()) return sorted(set(addrs), key=lambda x: x[0])
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'desymbolize'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '29']}; {'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': 'sort'}, {'id': '11', 'type': 'string', 'children': [], 'value': "'unknown'"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'content'}, {'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': 'binary'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'fast_memory_load'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '25', '28']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'addr'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bytes'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '34', 'type': 'list', 'children': ['35'], 'value': '[ content ]'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'content'}
def desymbolize(self): self.sort = 'unknown' content = self.binary.fast_memory_load(self.addr, self.size, bytes) self.content = [ content ]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'append_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'initial_content'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'readonly'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"unknown"'}; {'id': '14', 'type': 'block', 'children': ['15', '28', '37', '47', '72']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '17', '22']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'readonly'}, {'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': 'section_name'}, {'id': '21', 'type': 'string', 'children': [], 'value': '".rodata"'}; {'id': '22', 'type': 'else_clause', 'children': ['23']}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'section_name'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'.data'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'initial_content'}, {'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': 'initial_content'}; {'id': '36', 'type': 'string', 'children': [], 'value': 'b""'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'initial_content'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'initial_content'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ljust'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '46', 'type': 'string', 'children': [], 'value': 'b"\\x00"'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'Data'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54', '57', '60', '63', '66', '69']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'memory_data'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'section_name'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'section_name'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'initial_content'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'initial_content'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'size'}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76', '86']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '=='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'section_name'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'.rodata'"}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'extra_rodata'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '86', 'type': 'else_clause', 'children': ['87']}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'extra_data'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}
def append_data(self, name, initial_content, size, readonly=False, sort="unknown"): if readonly: section_name = ".rodata" else: section_name = '.data' if initial_content is None: initial_content = b"" initial_content = initial_content.ljust(size, b"\x00") data = Data(self, memory_data=None, section_name=section_name, name=name, initial_content=initial_content, size=size, sort=sort ) if section_name == '.rodata': self.extra_rodata.append(data) else: self.extra_data.append(data)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pop_job'}, {'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': 'returning'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '15', '38', '66']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '12']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': ['14']}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'if_statement', 'children': ['16', '18']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'returning'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_pop_job'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': '_jobs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '50']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'func_addr'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '42', 'type': 'argument_list', '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': '_jobs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '59']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '57']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'not'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'func_addr'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_returning_functions'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'continue_statement', 'children': []}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_pop_job'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'func_addr'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'None', 'children': []}
def pop_job(self, returning=True): if not self: return None if not returning: return self._pop_job(next(reversed(self._jobs.keys()))) for func_addr in reversed(self._jobs.keys()): if func_addr not in self._returning_functions: continue return self._pop_job(func_addr) return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_min_addr'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '32']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_regions'}, {'id': '11', 'type': 'block', 'children': ['12', '30']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '22']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '21'], 'value': '!='}; {'id': '14', 'type': 'attribute', 'children': ['15', '20']}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'project'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'arch'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'string', 'children': [], 'value': '"Soot"'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"self._regions is empty or not properly set."'}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'next'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_regions'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'irange'}
def _get_min_addr(self): if not self._regions: if self.project.arch.name != "Soot": l.error("self._regions is empty or not properly set.") return None return next(self._regions.irange())
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_job_sorting_key'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '37', '63', '102']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'MAX_BLOCKS_PER_FUNCTION'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1000000'}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'task_functions'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'reversed'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '22', 'type': 'generator_expression', 'children': ['23', '26', '31']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'task'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'function_address'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_task_stack'}, {'id': '31', 'type': 'if_clause', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'FunctionAnalysis'}, {'id': '37', 'type': 'try_statement', 'children': ['38', '50']}; {'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': 'function_pos'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'task_functions'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'job'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'func_addr'}; {'id': '50', 'type': 'except_clause', 'children': ['51', '52', '62']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '52', 'type': 'ERROR', 'children': ['53', '56', '58', '61']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '56', 'type': 'ERROR', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Function'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '%'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'return'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': [], 'value': ''}, {'id': '63', 'type': 'try_statement', 'children': ['64', '83']}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'block_in_function_pos'}; {'id': '68', 'type': 'call', 'children': ['69', '79']}, {'id': '69', 'type': 'attribute', 'children': ['70', '78']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_ordered_node_addrs'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'job'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'func_addr'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'addr'}, {'id': '83', 'type': 'except_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'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': 'block_in_function_pos'}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '99']}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '96'], 'value': '-'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'job'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'job'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'func_addr'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '-'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'MAX_BLOCKS_PER_FUNCTION'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'block_in_function_pos'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '*'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'MAX_BLOCKS_PER_FUNCTION'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'function_pos'}
def _job_sorting_key(self, job): MAX_BLOCKS_PER_FUNCTION = 1000000 task_functions = list(reversed( list(task.function_address for task in self._task_stack if isinstance(task, FunctionAnalysis)) )) try: function_pos = task_functions.index(job.func_addr) except ValueError: l.warning('Function address % return 0 try: block_in_function_pos = self._ordered_node_addrs(job.func_addr).index(job.addr) except ValueError: block_in_function_pos = min(job.addr - job.func_addr, MAX_BLOCKS_PER_FUNCTION - 1) return block_in_function_pos + MAX_BLOCKS_PER_FUNCTION * function_pos
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_merge_points'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'function_address'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '54']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '19']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'new_function'}; {'id': '12', 'type': 'subscript', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kb'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '19', 'type': 'except_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'list', 'children': [], 'value': '[ ]'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_function_merge_points'}; {'id': '30', 'type': 'block', 'children': ['31', '46']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ordered_merge_points'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'CFGUtils'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'find_merge_points'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'function_address'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'new_function'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'new_function'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_function_merge_points'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ordered_merge_points'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_function_merge_points'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'function_address'}
def _merge_points(self, function_address): try: new_function = self.kb.functions[function_address] except KeyError: return [ ] if function_address not in self._function_merge_points: ordered_merge_points = CFGUtils.find_merge_points(function_address, new_function.endpoints, new_function.graph) self._function_merge_points[function_address] = ordered_merge_points return self._function_merge_points[function_address]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_widening_points'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'function_address'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '66']}, {'id': '7', 'type': 'try_statement', 'children': ['8', '19']}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'new_function'}; {'id': '12', 'type': 'subscript', 'children': ['13', '18']}, {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kb'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '19', 'type': 'except_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'list', 'children': [], 'value': '[ ]'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '30']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_function_widening_points'}; {'id': '30', 'type': 'block', 'children': ['31', '43', '58']}, {'id': '31', 'type': 'if_statement', 'children': ['32', '36']}; {'id': '32', 'type': 'not_operator', 'children': ['33']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'new_function'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'normalized'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'new_function'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'widening_points'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'CFGUtils'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'find_widening_points'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'function_address'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'new_function'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'endpoints'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'new_function'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '65']}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': '_function_widening_points'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'function_address'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'widening_points'}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_function_widening_points'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'function_address'}
def _widening_points(self, function_address): try: new_function = self.kb.functions[function_address] except KeyError: return [ ] if function_address not in self._function_widening_points: if not new_function.normalized: new_function.normalize() widening_points = CFGUtils.find_widening_points(function_address, new_function.endpoints, new_function.graph) self._function_widening_points[function_address] = widening_points return self._function_widening_points[function_address]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_variables'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'collapse_same_ident'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '16', '23', '62']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'variables'}, {'id': '15', 'type': 'list', 'children': [], 'value': '[ ]'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'collapse_same_ident'}; {'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': 'NotImplementedError'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '28']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': '_variables'}; {'id': '28', 'type': 'block', 'children': ['29', '42', '55']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '40']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '34'], 'value': 'and'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'stack'"}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'var'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'SimStackVariable'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'continue_statement', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '53']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'reg'"}, {'id': '47', 'type': 'not_operator', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'SimRegisterVariable'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'continue_statement', 'children': []}, {'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': 'variables'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'variables'}
def get_variables(self, sort=None, collapse_same_ident=False): variables = [ ] if collapse_same_ident: raise NotImplementedError() for var in self._variables: if sort == 'stack' and not isinstance(var, SimStackVariable): continue if sort == 'reg' and not isinstance(var, SimRegisterVariable): continue variables.append(var) return variables
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_merge_points'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'function_addr'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'function_endpoints'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '7', 'type': 'block', 'children': ['8', '14', '39', '49', '59']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'merge_points'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '21']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '31']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '30'], 'value': '>'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'in_degree'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'merge_points'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ordered_merge_points'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'CFGUtils'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'quasi_topological_sort_nodes'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'merge_points'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'addrs'}; {'id': '52', 'type': 'list_comprehension', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'addr'}; {'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ordered_merge_points'}, {'id': '59', 'type': 'return_statement', 'children': ['60']}
def find_merge_points(function_addr, function_endpoints, graph): merge_points = set() for node in graph.nodes(): if graph.in_degree(node) > 1: merge_points.add(node) ordered_merge_points = CFGUtils.quasi_topological_sort_nodes(graph, merge_points) addrs = [n.addr for n in ordered_merge_points] return addrs
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reverse_post_order_sort_nodes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '31', '35', '52']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'post_order'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'networkx'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dfs_postorder_nodes'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '21', 'type': 'None', 'children': []}; {'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': 'reversed'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'post_order'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'addrs_to_index'}; {'id': '34', 'type': 'dictionary', 'children': []}, {'id': '35', 'type': 'for_statement', 'children': ['36', '39', '43']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'post_order'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '51']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'addrs_to_index'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'addr'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'return_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57', '67']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '59', 'type': 'lambda', 'children': ['60', '62']}; {'id': '60', 'type': 'lambda_parameters', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'addrs_to_index'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'addr'}, {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '69', 'type': 'True', 'children': []}
def reverse_post_order_sort_nodes(graph, nodes=None): post_order = networkx.dfs_postorder_nodes(graph) if nodes is None: return reversed(list(post_order)) addrs_to_index = {} for i, n in enumerate(post_order): addrs_to_index[n.addr] = i return sorted(nodes, key=lambda n: addrs_to_index[n.addr], reverse=True)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split'}, {'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': 'stash_splitter'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stash_ranker'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'state_ranker'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'from_stash'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'active'"}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'to_stash'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'stashed'"}, {'id': '23', 'type': 'block', 'children': ['24', '35', '126', '138', '145', '153', '161']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'states'}, {'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': '_fetch_states'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stash'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'from_stash'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '39', '49', '77', '108']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'stash_splitter'}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '45']}; {'id': '42', 'type': 'pattern_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stash_splitter'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '49', 'type': 'elif_clause', 'children': ['50', '53']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'stash_ranker'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54', '61']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'stash_ranker'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'pattern_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'keep'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '66', 'type': 'expression_list', 'children': ['67', '72']}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}, {'id': '69', 'type': 'slice', 'children': ['70', '71']}; {'id': '70', 'type': 'colon', 'children': []}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}; {'id': '74', 'type': 'slice', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '76', 'type': 'colon', 'children': []}, {'id': '77', 'type': 'elif_clause', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'is'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'state_ranker'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'block', 'children': ['82', '92']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'state_ranker'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '97', 'type': 'expression_list', 'children': ['98', '103']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}; {'id': '100', 'type': 'slice', 'children': ['101', '102']}, {'id': '101', 'type': 'colon', 'children': []}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ranked_paths'}, {'id': '105', 'type': 'slice', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '107', 'type': 'colon', 'children': []}; {'id': '108', 'type': 'else_clause', 'children': ['109']}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'pattern_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '115', 'type': 'expression_list', 'children': ['116', '121']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'states'}; {'id': '118', 'type': 'slice', 'children': ['119', '120']}, {'id': '119', 'type': 'colon', 'children': []}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'states'}, {'id': '123', 'type': 'slice', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'limit'}, {'id': '125', 'type': 'colon', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'pattern_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'map'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'keep'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_clear_states'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'from_stash'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_store_states'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'from_stash'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'keep'}, {'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': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_store_states'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'to_stash'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '161', 'type': 'return_statement', 'children': ['162']}
def split(self, stash_splitter=None, stash_ranker=None, state_ranker=None, limit=8, from_stash='active', to_stash='stashed'): states = self._fetch_states(stash=from_stash) if stash_splitter is not None: keep, split = stash_splitter(states) elif stash_ranker is not None: ranked_paths = stash_ranker(states) keep, split = ranked_paths[:limit], ranked_paths[limit:] elif state_ranker is not None: ranked_paths = sorted(states, key=state_ranker) keep, split = ranked_paths[:limit], ranked_paths[limit:] else: keep, split = states[:limit], states[limit:] keep, split = map(list, (keep, split)) self._clear_states(from_stash) self._store_states(from_stash, keep) self._store_states(to_stash, split) return self
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_executable_memory_regions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'force_segment'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '33', '37', '260', '291', '306']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16', '27']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'binaries'}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}, {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'project'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'loader'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'all_objects'}, {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'binaries'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '36', 'type': 'list', 'children': [], 'value': '[ ]'}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'binaries'}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '47', '114', '149', '195', '219', '229']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ELF'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '55', '84']}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '52'], 'value': 'and'}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'force_segment'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '61']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'is_executable'}; {'id': '66', 'type': 'block', 'children': ['67', '77']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '70', 'type': 'tuple', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'min_addr'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'max_addr'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '91']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'is_executable'}; {'id': '96', 'type': 'block', 'children': ['97', '107']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '100', 'type': 'tuple', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'min_addr'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'max_addr'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '114', 'type': 'elif_clause', 'children': ['115', '120']}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'PE'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'for_statement', 'children': ['122', '123', '126']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'if_statement', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'is_executable'}, {'id': '131', 'type': 'block', 'children': ['132', '142']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '135', 'type': 'tuple', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'min_addr'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'max_addr'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '149', 'type': 'elif_clause', 'children': ['150', '155']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'MachO'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'for_statement', 'children': ['162', '163', '166']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'if_statement', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'is_executable'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '177']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '177', 'type': 'block', 'children': ['178', '188']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '181', 'type': 'tuple', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'min_addr'}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'max_addr'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '195', 'type': 'elif_clause', 'children': ['196', '201']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'Blob'}, {'id': '201', 'type': 'block', 'children': ['202', '212']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '205', 'type': 'tuple', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'min_addr'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'max_addr'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'tpl'}, {'id': '219', 'type': 'elif_clause', 'children': ['220', '227']}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': '_cle_pseudo_objects'}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'pass_statement', 'children': []}, {'id': '229', 'type': 'else_clause', 'children': ['230']}; {'id': '230', 'type': 'block', 'children': ['231', '243', '253']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'l'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238']}, {'id': '237', 'type': 'string', 'children': [], 'value': '\'Unsupported object format "%s". Treat it as an executable.\''}; {'id': '238', 'type': 'attribute', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '246', 'type': 'tuple', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'min_addr'}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'max_addr'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'tpl'}; {'id': '260', 'type': 'if_statement', 'children': ['261', '263']}, {'id': '261', 'type': 'not_operator', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}, {'id': '267', 'type': 'list_comprehension', 'children': ['268', '276']}; {'id': '268', 'type': 'tuple', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '270', 'type': 'binary_operator', 'children': ['271', '272'], 'value': '+'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'backer'}; {'id': '276', 'type': 'for_in_clause', 'children': ['277', '280']}, {'id': '277', 'type': 'pattern_list', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'backer'}; {'id': '280', 'type': 'call', 'children': ['281', '290']}, {'id': '281', 'type': 'attribute', 'children': ['282', '289']}; {'id': '282', 'type': 'attribute', 'children': ['283', '288']}, {'id': '283', 'type': 'attribute', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'project'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'loader'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'memory'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'backers'}; {'id': '290', 'type': 'argument_list', 'children': []}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '300', 'type': 'lambda', 'children': ['301', '303']}, {'id': '301', 'type': 'lambda_parameters', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '306', 'type': 'return_statement', 'children': ['307']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'memory_regions'}
def _executable_memory_regions(self, objects=None, force_segment=False): if objects is None: binaries = self.project.loader.all_objects else: binaries = objects memory_regions = [ ] for b in binaries: if isinstance(b, ELF): if not force_segment and b.sections: for section in b.sections: if section.is_executable: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) else: for segment in b.segments: if segment.is_executable: tpl = (segment.min_addr, segment.max_addr) memory_regions.append(tpl) elif isinstance(b, PE): for section in b.sections: if section.is_executable: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) elif isinstance(b, MachO): if b.segments: for seg in b.segments: if seg.is_executable: for section in seg.sections: tpl = (section.min_addr, section.max_addr) memory_regions.append(tpl) elif isinstance(b, Blob): tpl = (b.min_addr, b.max_addr) memory_regions.append(tpl) elif isinstance(b, self._cle_pseudo_objects): pass else: l.warning('Unsupported object format "%s". Treat it as an executable.', b.__class__.__name__) tpl = (b.min_addr, b.max_addr) memory_regions.append(tpl) if not memory_regions: memory_regions = [(start, start + len(backer)) for start, backer in self.project.loader.memory.backers()] memory_regions = sorted(memory_regions, key=lambda x: x[0]) return memory_regions
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_debug_check'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'old_end'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'old_sort'}, {'id': '13', 'type': 'string', 'children': [], 'value': '""'}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '19']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '19', 'type': 'block', 'children': ['20', '38', '44']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '32']}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '27'], 'value': 'and'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '<='}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'old_end'}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': '=='}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'segment'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'old_sort'}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'raise_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'AngrCFGError'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}, {'id': '37', 'type': 'string', 'children': [], 'value': '"Error in SegmentList: blocks are not merged"'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'old_end'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'old_sort'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'segment'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'}
def _debug_check(self): old_end = 0 old_sort = "" for segment in self._list: if segment.start <= old_end and segment.sort == old_sort: raise AngrCFGError("Error in SegmentList: blocks are not merged") old_end = segment.end old_sort = segment.sort
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'next_pos_with_sort_not_in'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'max_distance'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '29', '131']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list_length'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'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': '_search'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '<'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list_length'}, {'id': '33', 'type': 'block', 'children': ['34', '42', '57', '80', '84']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'block'}, {'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': '_list'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '54']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'max_distance'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '<'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '+'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'max_distance'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'if_statement', 'children': ['58', '66']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62', '63'], 'value': '<='}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '66', 'type': 'block', 'children': ['67', '76']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '73']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': 'not'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'block'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorts'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'augmented_assignment', 'children': ['78', '79'], 'value': '+='}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '84', 'type': 'while_statement', 'children': ['85', '88']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '<'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'list_length'}; {'id': '88', 'type': 'block', 'children': ['89', '108', '127']}, {'id': '89', 'type': 'if_statement', 'children': ['90', '105']}; {'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'and'}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'is'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'max_distance'}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '<'}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '+'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'max_distance'}; {'id': '98', 'type': 'attribute', 'children': ['99', '104']}, {'id': '99', 'type': 'subscript', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '118']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '117'], 'value': 'not'}; {'id': '110', 'type': 'attribute', 'children': ['111', '116']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'sorts'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'attribute', 'children': ['121', '126']}, {'id': '121', 'type': 'subscript', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'return_statement', 'children': ['132']}
def next_pos_with_sort_not_in(self, address, sorts, max_distance=None): list_length = len(self._list) idx = self._search(address) if idx < list_length: block = self._list[idx] if max_distance is not None and address + max_distance < block.start: return None if block.start <= address < block.end: if block.sort not in sorts: return address idx += 1 i = idx while i < list_length: if max_distance is not None and address + max_distance < self._list[i].start: return None if self._list[i].sort not in sorts: return self._list[i].start i += 1 return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'occupied_by_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '28', '54', '81']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'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': '_search'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '25']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '24'], 'value': '<='}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'if_statement', 'children': ['29', '45']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '37', '38'], 'value': '<='}; {'id': '30', 'type': 'attribute', 'children': ['31', '36']}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '38', 'type': 'attribute', 'children': ['39', '44']}, {'id': '39', 'type': 'subscript', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '70']}, {'id': '55', 'type': 'boolean_operator', 'children': ['56', '59'], 'value': 'and'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '>'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '<'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'address'}, {'id': '61', 'type': 'attribute', 'children': ['62', '69']}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '-'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'attribute', 'children': ['73', '80']}, {'id': '73', 'type': 'subscript', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': '_list'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '-'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '81', 'type': 'return_statement', 'children': ['82']}
def occupied_by_sort(self, address): idx = self._search(address) if len(self._list) <= idx: return None if self._list[idx].start <= address < self._list[idx].end: return self._list[idx].sort if idx > 0 and address < self._list[idx - 1].end: return self._list[idx - 1].sort return None
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_binary_insert'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '24', '36', '75']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '<'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'ValueError'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'string', 'children': [], 'value': '"lo must be a non-negative number"'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'lst'}; {'id': '36', 'type': 'while_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '<'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'lo'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '40', 'type': 'block', 'children': ['41', '50']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '49'], 'value': '//'}, {'id': '45', 'type': 'parenthesized_expression', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '+'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'lo'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'hi'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '62', '69']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '<'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'lst'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'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': 'lo'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mid'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'hi'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mid'}, {'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': 'lst'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'lo'}
def _binary_insert(lst, elem, key, lo=0, hi=None): if lo < 0: raise ValueError("lo must be a non-negative number") if hi is None: hi = len(lst) while lo < hi: mid = (lo + hi) // 2 if key(lst[mid]) < key(elem): lo = mid + 1 else: hi = mid lst.insert(lo, elem)
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_io_counters'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortedby'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'io_counters'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sortedby_secondary'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'memory_percent'"}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '31'], 'value': '-'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '26'], 'value': '+'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '21'], 'value': '-'}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}, {'id': '17', 'type': 'subscript', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sortedby'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortedby'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '26', 'type': 'subscript', 'children': ['27', '30']}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sortedby'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sortedby'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '3'}
def _sort_io_counters(process, sortedby='io_counters', sortedby_secondary='memory_percent'): return process[sortedby][0] - process[sortedby][2] + process[sortedby][1] - process[sortedby][3]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_lambda'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortedby'}; {'id': '6', 'type': 'string', 'children': [], 'value': "'cpu_percent'"}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sortedby_secondary'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'memory_percent'"}; {'id': '10', 'type': 'block', 'children': ['11', '15', '33']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19', '24']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '=='}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sortedby'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'io_counters'"}, {'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': 'ret'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_sort_io_counters'}; {'id': '24', 'type': 'elif_clause', 'children': ['25', '28']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': '=='}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sortedby'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'cpu_times'"}; {'id': '28', 'type': 'block', 'children': ['29']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_sort_cpu_times'}, {'id': '33', 'type': 'return_statement', 'children': ['34']}
def _sort_lambda(sortedby='cpu_percent', sortedby_secondary='memory_percent'): ret = None if sortedby == 'io_counters': ret = _sort_io_counters elif sortedby == 'cpu_times': ret = _sort_cpu_times return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loop_position'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '26']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '10', '16']}, {'id': '7', 'type': 'pattern_list', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_sort_loop'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '23']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'glances_processes'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'return_statement', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'return_statement', 'children': ['27']}, {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}
def loop_position(self): for i, v in enumerate(self._sort_loop): if v == glances_processes.sort_key: return i return 0
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_event_sort_key'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event_type'}; {'id': '6', 'type': 'block', 'children': ['7', '37']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14', '19', '31']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'event_type'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'string', 'children': [], 'value': '"MEM"'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '18', 'type': 'string', 'children': [], 'value': "'memory_percent'"}, {'id': '19', 'type': 'elif_clause', 'children': ['20', '26']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'event_type'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'string', 'children': [], 'value': '"CPU_IOWAIT"'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'io_counters'"}, {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'cpu_percent'"}, {'id': '37', 'type': 'return_statement', 'children': ['38']}
def get_event_sort_key(self, event_type): if event_type.startswith("MEM"): ret = 'memory_percent' elif event_type.startswith("CPU_IOWAIT"): ret = 'io_counters' else: ret = 'cpu_percent' return ret
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_process_sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'event_type'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'glances_processes'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'auto_sort'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'glances_processes'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_key'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get_event_sort_key'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}
def set_process_sort(self, event_type): if glances_processes.auto_sort: glances_processes.sort_key = self.get_event_sort_key(event_type)